Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski 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.

Olivia86

Automotive
Joined
Sep 23, 2016
Messages
29
Location
IT
I'm trying to build a macro that, from a selection of different parts or assemblies it will traverse a list with a for a loop and make some operations.

While this sounds very simple, I'm struggling with it. I've found this example but only select the last part.


Any advice?
 
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

Back
Top