Move Annotations to Notes Area Annotation View Example (VBA)
This example shows
how to move all annotations to the Notes Area annotation view.
'----------------------------------------------
' Preconditions:
' 1. Open install_dir\samples\api\button.sldprt.
' 2. Add a note to the *Top annotation view by double-clicking
' *Top in the Annotations folder in the FeatureManager design
' tree and clicking Insert > Annotations > Note. If prompted
' to turn on feature dimensions display, click No.
' 3. Repeat step 2 to add a note to the *Front annotation view.
' 4. Double-click the Unassigned Items annotation view in the
' Annotations folder in the FeatureManager design tree.
' 5. Open the Immediate window.
'
' Postconditions:
' 1. Examine the Immediate window.
' 2. Double-click each annotation view in the FeatureManager
' design tree to verify that all annotations were moved
' from *Front and *Top to Notes Area only. If prompted
' to turn on feature dimensions display, click No.
'
' NOTE: Because the part is used elsewhere,
' do not save changes when closing the document.
'----------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelExt As SldWorks.ModelDocExtension
Dim swAnnViews As Variant
Dim annotations As Variant
Dim annToMove(1) As SldWorks.Annotation
Dim swAnnView As SldWorks.AnnotationView
Dim swAnn As SldWorks.Annotation
Dim swFeat As SldWorks.Feature
Dim i As Long
Dim j As Long
Dim k As Long
Dim status As Boolean
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelExt = swModel.Extension
'Get the annotation views, number of annotation views,
'and their names, and hides annotations in annotation views
'that are not activated
swAnnViews = swModelExt.AnnotationViews
Debug.Print "Number of annotation views: " & swModelExt.AnnotationViewCount
Debug.Print " Annotation view name: "
For i = 0 To swModelExt.AnnotationViewCount - 1
Set swAnnView = swAnnViews(i)
Set swFeat = swAnnView
Debug.Print " " & swFeat.Name
status = swAnnView.Hide
'status dependent on whether the annotation view is activated
'Only Unassigned Items is activated
Debug.Print " Hide: " & status
Next
'Iterate through each annotation view and its annotations
'Print each annotation name
'Add all annotations to an array to move them
k = 0
Debug.Print " Number of annotations in annotation view: "
For i = 0 To swModelExt.AnnotationViewCount - 1
Set swAnnView = swAnnViews(i)
swAnnView.Activate
annotations = swAnnView.annotations
Set swFeat = swAnnView
Debug.Print " " & swFeat.Name & " = " & swAnnView.AnnotationCount
If Not IsEmpty(annotations) Then
For j = 0 To swAnnView.AnnotationCount - 1
Set swAnn = annotations(j)
If k >= 0 Then
Set annToMove(k) = swAnn
k = k + 1
End If
Debug.Print " Annotation names:"
Debug.Print " " & swAnn.GetName
Next
End If
Next
'Move all annotations to the Notes Area annotation view
Debug.Print "Move all annotations to Notes Area annotation view:"
k = 0
For i = 0 To swModelExt.AnnotationViewCount - 1
Set swAnnView = swAnnViews(i)
swAnnView.Activate
Set swFeat = swAnnView
If swFeat.Name = "Notes Area" Then
status = swAnnView.MoveAnnotations(annToMove)
Debug.Print " Annotations moved: " & status
status = swAnnView.Show
'status should be false because annotation was activated
Debug.Print " Show: " & status
End If
Next
End Sub