Get Names of Annotations Example (VBA)
This example shows how to get the names of all of the annotations in
a drawing. This example also shows you how to get an annotation by name
and select it in a drawing.
'-------------------------------------
'
' Preconditions: Drawing document is open and has
' an
annotation named @MYADDIN-ANN1.
'
' Postconditions: The annotation named @MYADDIN-ANN1
' is
selected in the drawing.
'
'--------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swDrawing As SldWorks.DrawingDoc
Dim swModel As SldWorks.ModelDoc2
Dim swDrView As SldWorks.View
Dim curann As SldWorks.Annotation
Dim AnnArray As Variant
Dim vObj As Variant
Dim CurrAnn As SldWorks.Annotation
Sub main()
Set swApp = Application.SldWorks
Set swDrawing = swApp.ActiveDoc
Set swModel = swDrawing
swModel.ClearSelection2 True
Set swDrView = swDrawing.GetFirstView
While Not swDrView Is Nothing
AnnArray
= swDrView.GetAnnotations
If
Not IsEmpty(AnnArray) Then
For
Each vObj In AnnArray
Set
CurrAnn = vObj
Debug.Print
swDrView.GetName2, CurrAnn.GetName
If
CurrAnn.GetName = "@MYADDIN-ANN1"
Then
CurrAnn.Select3 True, Nothing
End
If
Next
vObj
End
If
Set
swDrView = swDrView.GetNextView
Wend
End Sub