×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Iterate trough assembly selection

Iterate trough assembly selection

Iterate trough assembly selection

(OP)
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.

https://help.solidworks.com/2017/english/api/sldwo...

Any advice?

RE: Iterate trough assembly selection

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 --> VBA

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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now
The Great Project Profitability Debate
A/E firms have a great opportunity to lead the world into the future, but the industry’s greatest asset—real-time data—is sitting wasted in clunky, archaic ERP platforms. Learn how real-time, fully interactive dashboards in a modern ERP allow you to unlock data that will shape the future of the world. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close