Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to automatically open drawing 1

Status
Not open for further replies.

arcticcatmatt

Mechanical
Mar 1, 2005
180
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.
 
Replies continue below

Recommended for you

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
 
^ You nailed it. Works like a charm. I was missing the
-6))& "SLDDRW" and I was using opendoc6.

THANKS!.. star for you :)
 
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
 
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
 
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.
 
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]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor