Select All Center Marks Example (VBA)
In the SolidWorks API, center marks can be features or annotations.
Use these enumerators with ISelectionMgr::GetSelectedObjectType3 to return
that specific type of center mark:
Traversal over the two types is different for the center marks that
are:
It is not directly possible to select center marks that are features,
even though they appear in a feature traversal. This example shows how
to indirectly select center marks that are features.
'------------------------------------------------
' Preconditions:
' (1)
Drawing is open.
' (2)
Drawing must contain at least one center mark.
'
' Postconditions: All center marks are selected.
'
'------------------------------------------------
Option Explicit
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc2
Dim
swModExt As
SldWorks.ModelDocExtension
Dim
swDraw As
SldWorks.DrawingDoc
Dim
swView As
SldWorks.View
Dim
vCtrMarkArr As
Variant
Dim
vCtrMark As
Variant
Dim
swCtrMark As
SldWorks.CenterMark
Dim
swAnn As
SldWorks.Annotation
Dim
swFeat As
SldWorks.feature
Dim
swSubFeat As
SldWorks.feature
Dim
swSubSubFeat As
SldWorks.feature
Dim
swSelMgr As
SldWorks.SelectionMgr
Dim
swSelData As
SldWorks.SelectData
Dim
bRet As
Boolean
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Set
swModExt = swModel.Extension
Set
swSelMgr = swModel.SelectionManager
Set
swSelData = swSelMgr.CreateSelectData
Set
swDraw = swModel
Set
swView = swDraw.GetFirstView
swModel.ClearSelection2 True
Debug.Print
"File = " & swModel.GetPathName
Do
While Not swView Is Nothing
Debug.Print
" View
= " & swView.Name
'
Traverse over annotation center marks
Set
swCtrMark = swView.GetFirstCenterMark
Do
While Not swCtrMark Is Nothing
Set
swAnn = swCtrMark.GetAnnotation
Debug.Print
" "
& swAnn.GetName
'
Select directly through annotation
bRet
= swAnn.Select3(True, swSelData):
Debug.Assert bRet
Set
swCtrMark = swCtrMark.GetNext
Loop
Set
swView = swView.GetNextView
Loop
Debug.Print
" ---------------"
'
Traverse over feature center marks
Set
swFeat = swModel.FirstFeature
While
Not swFeat Is Nothing
Set
swSubFeat = swFeat.GetFirstSubFeature
While
Not swSubFeat Is Nothing
Set
swSubSubFeat = swSubFeat.GetFirstSubFeature
While
Not swSubSubFeat Is Nothing
If
"CenterMark" = swSubSubFeat.GetTypeName
Then
Debug.Print
" "
& swSubSubFeat.Name
'
Cannot directly select through feature because does not
'
explicitly appear in FeatureManager design tree
'bRet
= swSubSubFeat.Select2(True, 0):
Debug.Assert bRet
'
Must indirectly select through user interface
bRet
= swModExt.SelectByID2(swSubSubFeat.Name,
"CENTERMARKS", 0#, 0#, 0#, True, 0, Nothing, swSelectOptionDefault):
Debug.Assert bRet
End
If
Set
swSubSubFeat = swSubSubFeat.GetNextSubFeature
Wend
Set
swSubFeat = swSubFeat.GetNextSubFeature
Wend
Set
swFeat = swFeat.GetNextFeature
Wend
End Sub