Professional Documents
Culture Documents
Create Body From Selected Faces Example
Create Body From Selected Faces Example
Create Body From Selected Faces Example
'-----------------------------------------' ' Problem: ' ' ' ' ' ' This example shows how to use some of the geometry and topolgy APIs to construct a temporary API body from a set of selected faces and then create a solid body feature from this temporary body.
' Preconditions: ' ' ' ' Postconditions: If the selected faces can be knitted into a solid, ' ' ' ' '------------------------------------------Option Explicit Public Enum swBodyType_e swAllBodies = -1 swSolidBody = 0 swSheetBody = 1 then a new part is created and the solid (from the selected faces) is inserted as an imported solid body feature. (1) Part is open. (2) At least one face is selected.
swWireBody = 2 swMinimumBody = 3 swGeneralBody = 4 swEmptyBody = 5 End Enum Public Enum swCreateFeatureBodyOpts_e swCreateFeatureBodyCheck = &H1 swCreateFeatureBodySimplify = &H2 End Enum Sub main() Dim swApp Dim swModel Dim swPart Dim swNewPart Dim swModeller Dim swSelMgr Dim swSelFace() Dim vFaceList Dim swBody Dim swNewBody Dim swFeat Dim nSelCount Dim i Dim bRet As SldWorks.SldWorks As SldWorks.ModelDoc2 As SldWorks.PartDoc As SldWorks.PartDoc As SldWorks.Modeler As SldWorks.SelectionMgr As SldWorks.face2 As Variant As SldWorks.body2 As SldWorks.body2 As SldWorks.feature As Long As Long As Boolean
Set swApp = CreateObject("SldWorks.Application") Set swModel = swApp.ActiveDoc Set swPart = swModel Set swSelMgr = swModel.SelectionManager Set swModeller = swApp.GetModeler
nSelCount = swSelMgr.GetSelectedObjectCount
ReDim swSelFace(nSelCount - 1)
vFaceList = swSelFace
If swNewBody Is Nothing Then Debug.Print "Failed to form solid body from selected faces."
' Force creation of a solid body feature Set swFeat = swNewPart.CreateFeatureFromBody3(swNewBody, False, _ swCreateFeatureBodyCheck + swCreateFeatureBodySimplify)
' Must be able to create a solid body feature from a solid body Debug.Assert Not swFeat Is Nothing