Hide Table of Contents

Move Annotations to First Annotation View Example (VB.NET)

This example shows how to move annotations to the Unassigned Items annotation view.

'----------------------------------------------
' Preconditions:
' 1. Open a part or assembly document.
' 2. Add a note to the *Top annotation view. 
' 3. Add a note to the *Front annotation view.
'    NOTES
'    * If necessary, create *Top and *Front 
'      annotation views.
'    * If prompted to turn on feature dimensions
'      display, click No.
' 4. Open the Immediate window.
' 5. Run the macro.
'
' Postconditions:
' 1. Prints the names of the annotation views and notes
'    to the Immediate window.
' 2. Moves both notes to the Unassigned Items
'    annotation view.
' 3. Double-click each annotation view in the Annotations
'    folder in the FeatureManager design tree to verify.
'----------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
 
Partial Class SolidWorksMacro
 
    Public Sub Main()
 
        Dim swModel As ModelDoc2
        Dim swModelExt As ModelDocExtension
        Dim swAnnViews As Object
        Dim annotations As Object
        Dim annToMove(1) As Annotation
        Dim swAnnView As AnnotationView
        Dim swAnn As Annotation
        Dim swFeat As Feature
        Dim i As Integer
        Dim j As Integer
        Dim k As Integer
        Dim status As Boolean
 
        swModel = swApp.ActiveDoc
        swModelExt = swModel.Extension
        swAnnViews = swModelExt.AnnotationViews

        'Activate each view
        'Only one view can be active at a time
        For i = 0 To swModelExt.AnnotationViewCount - 1
            swAnnView = swAnnViews(i)
            swFeat = swAnnView
            Debug.Print("Annotation view name: " & swFeat.Name)
            swAnnView.Activate()
            'Alternative to activate
            'swAnnView.ActivateAndReorient
        Next
 
        'Print each annotation name and add all annotations to an array
        For i = 0 To swModelExt.AnnotationViewCount - 1
            swAnnView = swAnnViews(i)
            swAnnView.Activate()
            annotations = swAnnView.annotations
            If IsNothing(annotations) = False Then
                For j = 0 To UBound(annotations)
                    swAnn = annotations(j)
                    annToMove(j) = swAnn
                    Debug.Print("Annotation name: " & swAnn.GetName)
                Next
            End If
 
            'Move all annotations to first annotation view, Unassigned Items
            If i > 0 Then
                swAnnView = swAnnViews(i)
                status = swAnnView.MoveAnnotations(annToMove)
                Debug.Assert(status)
            End If
        Next
    End Sub
 
 
    ''' <summary>
    ''' The SldWorks swApp variable is pre-assigned for you.
    ''' </summary>
    Public swApp As SldWorks
 
 
End Class


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:   Move Annotations to First Annotation View Example (VB.NET)
*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) 2013 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.