Hide Table of Contents

Get Where Annotations Can be Shown Example (VBA)

This example shows how to get the names of the annotation views where an annotation can be shown.

'----------------------------------------------
' Preconditions:
' 1. Open a part document with one or more annotations
'    in one or more annotation views.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Gets the annotation views. 
' 2. Iterates through the annotation views and annotations.
' 3. Prints the name of each annotation view and number of 
'    annotations in that annotation view.
' 4. Prints whether each annotation in that annotation view
'    can be shown in the other annotation views and in 
'    multiple annotation views.
' 5. Examine the Immediate window.
'----------------------------------------------
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 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 nbrAnnotations As Long
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swModelExt = swModel.Extension    
    'Get the annotation views
    swAnnViews = swModelExt.AnnotationViews
    For i = 0 To swModelExt.AnnotationViewCount - 1
        Set swAnnView = swAnnViews(i)
    Next
    Debug.Print "Number of annotation views = " & swModelExt.AnnotationViewCount
    Debug.Print ""    
    'Iterate through the annotation views and annotations
    'Print the name of each annotation view and number of annotations
    'in that annotation view 
    'Print whether each annotation in that annotation view
    'can be shown in the other annotation views and in 
    'multiple annotation views
    Debug.Print "  Name of annotation view and number of annotations in the annotation view "
    Debug.Print ""
    For i = 0 To swModelExt.AnnotationViewCount - 1
        Set swAnnView = swAnnViews(i)
        swAnnView.Activate
        annotations = swAnnView.GetAnnotations2(False, False)
        Set swFeat = swAnnView
        nbrAnnotations = swAnnView.AnnotationCount
        If nbrAnnotations > 0 Then
          Debug.Print ""
        End If
        Debug.Print "        " & swFeat.Name & " = " & nbrAnnotations
                If Not IsEmpty(annotations) Then
                        j = 0
                        For j = 0 To nbrAnnotations - 1
                                Debug.Print "          Can show annotation " & j + 1 & " in these annotation views: "
                                Set swAnn = annotations(j)
                                For k = 0 To swModelExt.AnnotationViewCount - 1
                                    Set swAnnView = swAnnViews(k)
                                    Set swFeat = swAnnView
                                    Debug.Print "              " & swFeat.Name & " = " & swAnn.CanShowInAnnotationView(swFeat.Name)
                                Next k
                                Debug.Print "              multiple = " & swAnn.CanShowInMultipleAnnotationViews()
                                Debug.Print ""
                        Next j
                End If
    Next i    
End Sub


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get Where Annotations Can be Shown Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2023 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.