Create Body From Selected Faces Example

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

SolidWorks API Help Create Body From Selected Faces Example This example shows how to create a body

from one or more selected faces using: IBody2::CreateBodyFromFaces IPartDoc::CreateFeatureFromBody3

'-----------------------------------------' ' 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)

For i = 1 To nSelCount Set swSelFace(i - 1) = swSelMgr.GetSelectedObject5(i) Next

vFaceList = swSelFace

Set swBody = swPart.CreateNewBody Set swNewBody = swBody.CreateBodyFromFaces(nSelCount, (vFaceList))

If swNewBody Is Nothing Then Debug.Print "Failed to form solid body from selected faces."

Exit Sub End If

Debug.Assert swSolidBody = swNewBody.GetType

Set swNewPart = swApp.NewPart

' 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

End Sub '------------------------------------------

You might also like