Get filename of selected part in Solidworks drawing and copy to clipboard.

Is it possible to use a macro to get the filename of a selected part in a drawing and copy it to the clipboard?

This helps me a lot as oftentimes I need to lookup the drawings of certain parts in a drawing and I would hover my cursor over the part, remember the filename that appears, and then type it out somewhere else. Thanks a lot!!!

SolidworksApi/macros
Answers 3
AT
AT 2021-04-09 Best Answer

Take a look at this macro: Copy Component Path

You might want to use this technique: Creating Macro Buttons so you can assign the macro to a button and add shortcuts.

DG
DG 2021-04-09

Thanks for the shout-out ​, glad to know that the codes were helpful.

And yes we all love the forums as it bounds our community

AH
AH 2021-04-09

Thank you so much! With a bit more research, I finally got it to work the way I want.

The macro gives me the path name, but what I wanted was the filename. And searching this forum gave me the other half of the solution (from 'How to get only child component's name while traversing assembly in macro'). Shout-out to ​

<p></p><p style="font-size: 14px; font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">Dim swCompName As String</p><p style="font-size: 14px; font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">swCompName = Mid(swCompModel.GetPathname, InStrRev(swCompModel.GetPathname, "\") + 1)</p><p style="font-size: 14px; font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">swCompName = Left(swCompName , InStrRev(swCompName , ".") - 1)</p><p></p>

And then I concatenated it with some other strings to form a URL and used the following code (from "Hyperlink in VBA UserForm") to open it.

<p><span style="color: #333333; font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; font-size: 14px;">Shell "rundll32.exe url.dll,FileProtocolHandler " & URL</span></p>

I love this forum! Sharing what I learnt as my way of paying it forward. Hopefully its useful to someone else in future