Hide Table of Contents

Traverse Annotations Example (VBA)

This example shows how to visit all display dimension annotations in a selected sketch in an open model by using the IFeature::GetFirstDisplayDimension and IFeature::GetNextDisplayDimension methods.

First open a SolidWorks model, and select a sketch containing one or more Dimension objects. Use ISelectionMgr to access the selected sketch, and call IFeature::GetFirstDisplayDimension to obtain the first IDisplayDimension in the sketch. Then enter a loop that iterates while IDisplayDimension is not Nothing.

Inside the loop, retrieve the annotation that contains the IDisplayDimension with a call to IDisplayDimension::GetAnnotation, and get the position of the annotation by calling IAnnotation::GetPosition. The VARIANT array returned by IAnnotation::GetPosition can be modified and the position of the annotation can be updated to reflect this change with a call to IAnnotation::SetPosition. The next IDisplayDimension in the loop is obtained with a call to IFeature::GetNextDisplayDimension.

The code to move all IDisplayDimension annotations 100 mm to the right (in the x dimension) is as follows.

 

'---------------------------------------------

Option Explicit

 

    Dim swApp As SldWorks.SldWorks

    Dim Model As SldWorks.ModelDoc2

    Dim selMgr As SldWorks.SelectionMgr

    Dim CurAnnotation As SldWorks.Annotation

    Dim AnnotationPosition As Variant

    Dim CurFeature As SldWorks.feature

    Dim DispDim As SldWorks.DisplayDimension

    

Sub main()

        

    'Attach the program to SolidWorks application

    Set swApp = CreateObject("SldWorks.Application")

    'Get the model

    Set Model = swApp.ActiveDoc

    Set selMgr = Model.SelectionManager

    

   ' Get the selected sketch

    Set CurFeature = selMgr.GetSelectedObject5(1)

    'Get the first DisplayDimension in the selected sketch

    Set DispDim = CurFeature.GetFirstDisplayDimension

    

    'Iterate through all of the display dimensions in the sketch

    Do While Not DispDim Is Nothing

        'Retrieve the annotation from display dimension

        Set CurAnnotation = DispDim.GetAnnotation

        

        'Get the position of the annotation

        AnnotationPosition = CurAnnotation.GetPosition

        

        'If there is no problem obtaining the position

        If Not IsNull(AnnotationPosition) Then

            'Move the annotation to the right

            CurAnnotation.SetPosition AnnotationPosition(0) + 0.1, AnnotationPosition(1), AnnotationPosition(2)

        End If

        

        'Get the next display dimension

        Set DispDim = CurFeature.GetNextDisplayDimension(DispDim)

    Loop

    

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:   Traverse Annotations 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) 2012 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.