MACRO LIBRARY

Get the edges used by a dimension

Free public access. No account or subscription required.

Files

Get the edges used by a dimension

Code

'Demonstrates how to get the entities attached to an annotation. In this case, user _
    selects a dimension, runs the macro, and the edges to which the dimension is _
    attached are selected.
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
'Preconditions: drawing is open, drawing view dimension is selected.
'Postconditions: edges to which dimension are attached are selected.
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swSelData As SldWorks.SelectData
Dim swDispDim As SldWorks.DisplayDimension
Dim swAnn As SldWorks.Annotation
Dim swEnt As SldWorks.Entity
Dim swEdge As SldWorks.Edge
    
Dim vAttachedEntTypes As Variant
Dim vAttachedEnt As Variant
Dim i As Integer
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swDraw = swModel
    Set swSelMgr = swModel.SelectionManager
    Set swSelData = swSelMgr.CreateSelectData
    
    If swSelMgr.GetSelectedObjectType3(1, -1) = swSelectType_e.swSelDIMENSIONS Then
        Set swDispDim = swSelMgr.GetSelectedObject6(1, -1)
    Else
        MsgBox "Select a dimension"
    End If
    
    swModel.ClearSelection2 True
    
    Set swAnn = swDispDim.GetAnnotation
    vAttachedEnt = swAnn.GetAttachedEntities3
    vAttachedEntTypes = swAnn.GetAttachedEntityTypes
    For i = 0 To UBound(vAttachedEntTypes)
        If vAttachedEntTypes(i) = swSelectType_e.swSelEDGES Then
            Set swEnt = vAttachedEnt(i)
            swEnt.Select4 True, swSelData
        End If
    Next i
End Sub