Thicken Sheet Body Example (VBA)
This example shows how to thicken a sheet (surface) body.
'--------------------------------
'
' Preconditions: Part document is open and a
' sheet
body is selected.
'
' Postconditions: Sheet body is thickened to
' create
a temporary thickened body.
'
'--------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Sub main()
Dim
swModel As
SldWorks.ModelDoc2
Dim
swPart As
SldWorks.PartDoc
Dim
swBody As
SldWorks.Body2
Dim
dThickness As
Double
Dim
swFace As
SldWorks.Face2
Dim
swOriginalSheetBody As
SldWorks.Body2
Dim
swModeler As
SldWorks.Modeler
Dim
vSheets As
Variant
Dim
lOptions As
Long
Dim
lErrors As
Long
Dim
lNumSheets As
Long
Dim
aBodies(0) As
SldWorks.Body2
Dim
vBodies As
Variant
Dim
swFeature As
SldWorks.Feature
'
Thickness
dThickness
= 0.01
'
Connect to SOLIDWORKS
Set
swApp = Application.SldWorks
'
Get modeler
Set
swModeler = swApp.GetModeler
Debug.Assert
Not swModeler Is Nothing
'
Get active document
Set
swModel = swApp.ActiveDoc
'
Cast down to part
Set
swPart = swModel
'
Get the selected sheet body
Set
swBody = swModel.SelectionManager.GetSelectedObject6(1,
-1)
'
Make a copy, so you can later sew together with other sheets
Set
swOriginalSheetBody = swBody.Copy
Set
swThickenedBody = swModeler.ThickenSheet(swOriginalSheetBody,
dThickness, swThickenDirection_Side1)
Debug.Assert
(Not (swThickenedBody Is Nothing))
Debug.Assert
(swThickenedBody.GetType = swBodyType_e.swSolidBody)
Set
aBodies(0) = swThickenedBody
vBodies
= aBodies
'
Turn temporary body into a feature
Set
swFeature = swPart.CreateFeatureFromBody3(vBodies(0),
False, swCreateFeatureBodyOpts_e.swCreateFeatureBodyCheck)
swModel.EditRebuild3
End Sub