MACRO LIBRARY

Lesson 3.4 SelectionManager code

Free public access. No account or subscription required.

Files

Lesson 3.4 SelectionManager code

Code

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    
    For i = 1 To swSelMgr.GetSelectedObjectCount2(-1)
        If swSelMgr.GetSelectedObjectType3(i, -1) <> swSelBODYFEATURES Then
            MsgBox "Selected object is not a body feature."
        Else
            Set swFeat = swSelMgr.GetSelectedObject6(i, -1)
            MsgBox "Feature name: " & swFeat.Name
        End If
    Next i
End Sub