This website uses cookies to ensure you get the best experience on our website. By using our website you agree on the following Cookie Policy, Privacy Policy, and Terms Of Use
This macro creates individual surface (sheet) body for each face of the selected solid or surface body using the IModeler::CreateSheetFromFaces SOLIDWORKS API method.
Dim swApp As SldWorks.SldWorks
Sub main()
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
IfNot swModel IsNothingThenDim swSelMgr As SldWorks.SelectionMgr
Set swSelMgr = swModel.SelectionManager
Dim swBody As SldWorks.Body2
Set swBody = swSelMgr.GetSelectedObject6(1, -1)
IfNot swBody IsNothingThen
SplitBodyFaces swModel, swBody
Else
MsgBox "Please select body"EndIfElse
MsgBox "Please open part"EndIfEndSubSub SplitBodyFaces(part As SldWorks.PartDoc, body As SldWorks.Body2)
Dim swModeler As SldWorks.Modeler
Set swModeler = swApp.GetModeler
Dim vFaces AsVariant
vFaces = body.GetFaces
Dim i AsIntegerFor i = 0 To UBound(vFaces)
Dim swFace(0) As SldWorks.Face2
Set swFace(0) = vFaces(i)
Dim swSheetBody As SldWorks.Body2
Set swSheetBody = swModeler.CreateSheetFromFaces(swFace)
part.CreateFeatureFromBody3 swSheetBody, True, swCreateFeatureBodyOpts_e.swCreateFeatureBodySimplify
NextEndSub