×
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!
  • Students Click Here

*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

Jobs

Macro to automatically open drawing

Macro to automatically open drawing

Macro to automatically open drawing

(OP)
Currently when we have a part up and we want to see the drawing, we right click on the file name in the feature tree, then "open drawing".

Some users keep constantly searching for "open drawing". Some times it isn't there and they have to hit that little arrow to show more options, then it appears.

I want to simplify this even more and make it just a click of a button.

Have your part/assembly open. Click the button, and the drawing of it opens up.

I have searched and did not find one already written. I tried writing one yesterday and got close.. but it kept opening the same drawing over and over again and not the drawing of the current part.
 

RE: Macro to automatically open drawing

Not too difficult.  As long as the drawings are in the same path as the parts/assemblies, this should suffice...

Dim swApp As Object
Dim sFileName As String
Dim Part As Object

Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc

sFileName = Left$(Part.GetPathName, (Len(Part.GetPathName) - 6)) & "SLDDRW"
Set Part = swApp.OpenDoc(sFileName, swDocDRAWING)

End Sub

RE: Macro to automatically open drawing

(OP)
^ You  nailed it. Works like a charm. I was missing the  
-6))& "SLDDRW" and I was using opendoc6.

THANKS!.. star for you :)

RE: Macro to automatically open drawing

You may also want to add a couple lines to check that the drawing actually exists so you don't get a run time error:

Dim swApp As Object
Dim sFileName As String
Dim Part As Object

Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc

Set fso = CreateObject("Scripting.FileSystemObject")
sFileName = Left$(Part.GetPathName, (Len(Part.GetPathName) - 6)) & "SLDDRW"
If fso.FileExists(sFileName) Then
    Set Part = swApp.OpenDoc(sFileName, swDocDRAWING)
    Else: MsgBox ("Drawing does not exist")
End If

End Sub

RE: Macro to automatically open drawing

About "that little arrow".  You can click on the customize selection at the bottom of the menu and permenately add Open Drawing to the menu....of course, that still requires hunting around for it cuz it's in like 5 different places, depending on your context.

Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group

RE: Macro to automatically open drawing

If you click the "Make drawing from part/assembly" button on the topmost toolbar, SolidWorks will search first if there is a drawing with the same name as the open part/assembly.  If none exist, it will create a new one.  This should solve what you are trying to do without any macros.

RE: Macro to automatically open drawing

arcticcatmatt'

On the machines which aren't showing the full menu selections, RMB on a Toolbar area and select Customize > Options then select both Show All buttons. This will force all the available selections in all drop-down menus to be displayed.

cheers

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!


Resources