Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations pierreick on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Iterate trough assembly selection

Status
Not open for further replies.
Replies continue below

Recommended for you

Hello,
Select some components in the selection tree, then run the code below.
It will give their name in the order of the selection.

Code:
Option Explicit
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swSelMgr As SldWorks.SelectionMgr
    Dim swSelComp As SldWorks.Component2
    Dim i As Integer
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    For i = 1 To swSelMgr.GetSelectedObjectCount2(-1)
        If swSelMgr.GetSelectedObjectType3(i, -1) = swSelectType_e.swSelCOMPONENTS Then
            Set swSelComp = swSelMgr.GetSelectedObjectsComponent3(i, -1)
            Debug.Print "Component #" & i & " : " & swSelComp.Name2
        End If
    Next
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor