Get Selected Assembly Part

Programming and macros
User avatar
tk421
Posts: 8
Joined: Thu Aug 24, 2023 5:33 pm
Answers: 1
Location: Milwaukee, WI
x 4
x 1

Get Selected Assembly Part

Unread post by tk421 »

Hello fellow users, hopefully this is an easy one for you: I'd like to get the selected part in my assembly via macro. I'm close (i think) to the kitchen, I can smell the food, but I can't find the door. I think I need to use GetSelectedMember(), but I can't close the deal. Would one of you be good enough to look at my code and lmk where or what I need to change? Thanks in advance! David

Code: Select all

Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swExt As SldWorks.ModelDocExtension
Dim swSelMgr As SldWorks.SelectionMgr
Dim swComp As SldWorks.Component2
Dim swAssem As SldWorks.AssemblyDoc
Dim featMgr As SldWorks.FeatureManager
Dim selMgr As SldWorks.SelectionMgr
Dim selComp As SldWorks.Component2

     Sub main()
          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          Set swExt = swModel.Extension
          Set swSelMgr = swModel.SelectionManager
          Set featMgr = swModel.FeatureManager
          Set swAssem = swModel
          Set selComp = swAssem.GetSelectedMember
          Dim d As String
          
          Set d = selComp.Name

          swApp.SendMsgToUser d        
     End Sub
by tk421 » Fri Aug 25, 2023 7:49 am
Came back with new patience this morning and found this thread https://cadforum.net/viewtopic.php?t=492 posted in the SW General forum. That thread contained what i needed and more!

I've been programming macros & plugins in PowerMill for over 10 years now. My job is shifting to more design than programming so now I'm going to start automating regular tasks in SW. I should be a regular on this forum for some time to come. VBA is a new animal to me but it looks like there are many seasoned programmers on here that are willing to help!

This forum looks loads better that the "official" SW forum & easier to navigate... Reminds me of the old Delcam forums before Auto**** bought them. I look forward to interacting with everyone!

David
<><
Go to full post
David
<><
-----------------------------------
the numbers never lie

www.accuratepattern.com
User avatar
tk421
Posts: 8
Joined: Thu Aug 24, 2023 5:33 pm
Answers: 1
Location: Milwaukee, WI
x 4
x 1

Re: Get Selected Assembly Part

Unread post by tk421 »

Came back with new patience this morning and found this thread https://cadforum.net/viewtopic.php?t=492 posted in the SW General forum. That thread contained what i needed and more!

I've been programming macros & plugins in PowerMill for over 10 years now. My job is shifting to more design than programming so now I'm going to start automating regular tasks in SW. I should be a regular on this forum for some time to come. VBA is a new animal to me but it looks like there are many seasoned programmers on here that are willing to help!

This forum looks loads better that the "official" SW forum & easier to navigate... Reminds me of the old Delcam forums before Auto**** bought them. I look forward to interacting with everyone!

David
<><
David
<><
-----------------------------------
the numbers never lie

www.accuratepattern.com
Post Reply