Get Mirror Solid Feature Data Example (VBA)
This example shows how to get mirror solid feature data.
'----------------------------------------
'
' Preconditions:
' (1)
Model document is open.
' (2)
Mirror solid feature is selected.
'
' Postconditions: None
'
'-----------------------------------------
Option Explicit
Public Enum swSelectType_e
swSelFACES
= 2 '
"FACE"
swSelDATUMPLANES
= 4 '
"PLANE"
swSelREFSURFACES
= 27 '
"REFSURFACE"
End Enum
Public Enum swBodyType_e
swAllBodies
= -1
swSolidBody
= 0
swSheetBody
= 1
swWireBody
= 2
swMinimumBody
= 3
swGeneralBody
= 4
swEmptyBody
= 5
End Enum
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc2
Dim
swSelMgr As
SldWorks.SelectionMgr
Dim
swSelData As
SldWorks.SelectData
Dim
swFeat As
SldWorks.feature
Dim
swMirrorSolid As
SldWorks.MirrorSolidFeatureData
Dim
swBody As
SldWorks.body2
Dim
swFace As
SldWorks.face2
Dim
swRefPlane As
SldWorks.refPlane
Dim
swEnt As
SldWorks.Entity
Dim
swFaceFeat As
SldWorks.feature
Dim
swRefPlaneFeat As
SldWorks.RefPlaneFeatureData
Dim
vPlaneParam As
Variant
Dim
vBody As
Variant
Dim
i As
Long
Dim
bRet As
Boolean
Set
swApp = CreateObject("SldWorks.Application")
Set
swModel = swApp.ActiveDoc
Set
swSelMgr = swModel.SelectionManager
Set
swSelData = swSelMgr.CreateSelectData
Set
swFeat = swSelMgr.GetSelectedObject5(1)
Set
swMirrorSolid = swFeat.GetDefinition
'
Disable Visual Basic error on Query Interface
On
Error Resume Next
Debug.Print
"File = " & swModel.GetPathName
Debug.Print
" "
& swFeat.Name
Debug.Print
" PatternBodyCount
=
" & swMirrorSolid.GetPatternBodyCount
Debug.Print
" Merge
=
" & swMirrorSolid.Merge
Debug.Print
" KnitSurface
=
" & swMirrorSolid.KnitSurface
'
Roll back to get to the faces and features
bRet
= swMirrorSolid.AccessSelections(swModel,
Nothing): Debug.Assert bRet
'
Face or reference surface
Set
swFace = swMirrorSolid.Face
Set
swEnt = swMirrorSolid.Face
'
Reference plane
Set
swFaceFeat = swMirrorSolid.Face
Set
swRefPlane = swFaceFeat.GetSpecificFeature
Set
swRefPlaneFeat = swFaceFeat.GetDefinition
'
Reference plane also presents Entity interface
Debug.Assert
Not swEnt Is Nothing
Debug.Print
" Face
Type =
" & swEnt.GetType
swModel.ClearSelection2 True
If
Not swFaceFeat Is Nothing Then
Debug.Print
" Feat
Type =
" & swFaceFeat.GetTypeName
bRet
= swFaceFeat.Select2(True, 0)
Else
bRet
= swEnt.Select4(True, swSelData)
End
If
Debug.Assert
bRet
If
bRet Then Stop
swModel.ClearSelection2 True
vBody
= swMirrorSolid.PatternBodyArray
For
i = 0 To UBound(vBody)
Set
swBody = vBody(i)
bRet
= swBody.Select(True, 0): Debug.Assert
bRet
Debug.Print
" Body("
& i & ") =
" & swBody.GetType
Next
i
If
bRet Then Stop
'
Update feature
bRet
= swFeat.ModifyDefinition(swMirrorSolid,
swModel, Nothing): Debug.Assert bRet
End Sub