Hide Table of Contents

Select All Center Marks Example (VBA)

In the SolidWorks API, center marks can be features or annotations. Use these enumerators with ISelectionMgr::GetSelectedObjectType3 to return that specific type of center mark:

  • swSelCENTERMARKS for center marks that are features

  • swSelCENTERMARKSSYMS for center marks that are annotations

Traversal over the two types is different for the center marks that are:

  • Annotations. Use IView::GetFirstCenterMark and ICenterMark::GetNext

  • Features. Use IView::GetCenterMarks.

It is not directly possible to select center marks that are features, even though they appear in a feature traversal. This example shows how to indirectly select center marks that are features.

 

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

' Preconditions:

'       (1) Drawing is open.

'       (2) Drawing must contain at least one center mark.

'

' Postconditions: All center marks are selected.

'

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

Option Explicit

Sub main()

    Dim swApp                       As SldWorks.SldWorks

    Dim swModel                     As SldWorks.ModelDoc2

    Dim swModExt                    As SldWorks.ModelDocExtension

    Dim swDraw                      As SldWorks.DrawingDoc

    Dim swView                      As SldWorks.View

    Dim vCtrMarkArr                 As Variant

    Dim vCtrMark                    As Variant

    Dim swCtrMark                   As SldWorks.CenterMark

    Dim swAnn                       As SldWorks.Annotation

    Dim swFeat                      As SldWorks.feature

    Dim swSubFeat                   As SldWorks.feature

    Dim swSubSubFeat                As SldWorks.feature

    Dim swSelMgr                    As SldWorks.SelectionMgr

    Dim swSelData                   As SldWorks.SelectData

    

    Dim bRet                        As Boolean

    

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swModExt = swModel.Extension

    Set swSelMgr = swModel.SelectionManager

    Set swSelData = swSelMgr.CreateSelectData

    Set swDraw = swModel

    Set swView = swDraw.GetFirstView

    

    swModel.ClearSelection2 True

    

    Debug.Print "File = " & swModel.GetPathName

    

    Do While Not swView Is Nothing

        Debug.Print "  View = " & swView.Name

        

        ' Traverse over annotation center marks

        Set swCtrMark = swView.GetFirstCenterMark

        Do While Not swCtrMark Is Nothing

            Set swAnn = swCtrMark.GetAnnotation

            

            Debug.Print "    " & swAnn.GetName

            

            ' Select directly through annotation

            bRet = swAnn.Select3(True, swSelData): Debug.Assert bRet

            

            Set swCtrMark = swCtrMark.GetNext

        Loop

                

        Set swView = swView.GetNextView

    Loop

        

    Debug.Print "  ---------------"

    

    ' Traverse over feature center marks

    Set swFeat = swModel.FirstFeature

    While Not swFeat Is Nothing

        Set swSubFeat = swFeat.GetFirstSubFeature

        While Not swSubFeat Is Nothing

            Set swSubSubFeat = swSubFeat.GetFirstSubFeature

            While Not swSubSubFeat Is Nothing

                If "CenterMark" = swSubSubFeat.GetTypeName Then

                    Debug.Print "  " & swSubSubFeat.Name

                    

                    ' Cannot directly select through feature because does not

                    ' explicitly appear in FeatureManager design tree

                    'bRet = swSubSubFeat.Select2(True, 0): Debug.Assert bRet

                    

                    ' Must indirectly select through user interface

                    bRet = swModExt.SelectByID2(swSubSubFeat.Name, "CENTERMARKS", 0#, 0#, 0#, True, 0, Nothing, swSelectOptionDefault): Debug.Assert bRet

                End If

                Set swSubSubFeat = swSubSubFeat.GetNextSubFeature

            Wend

            

            Set swSubFeat = swSubFeat.GetNextSubFeature

        Wend

        

        Set swFeat = swFeat.GetNextFeature

    Wend

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:   Select All Center Marks 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.