ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
JKJason Kearney17/08/2012

Hello,

Does anyone know how to use the OpenDoc6 Method to open a shortcut to a Solidworks file?
I have some rusty programming experience, but I am pretty new to VBA and the API. I am attempting to write a macro to open a drawing based on the active configurations name, but some of the drawings we have are grouped by name to make product-wide changes easier to implement. In this scenario, I saved the assembly and drawing with one naming convention( "900Options.SLDASM" and "900Options.SLDDRW" ) and refer any product option numbers to it through configuration names and shortcuts( Config. 900561A to "900561A.SLDDRW.lnk", Config.900561B to "900561B.SLDDRW.lnk" etc. So I have constructed the following code to compensate if the first OpenDoc6 (refering to the drawing by configuration name) fails, to try again with the shortcut. The first segment works, if the drawing and configuration have the same name. However, when it goes into the "if" segement, it won't open the shortcut and my object always comes back = Nothing.

Dim swApp As Object

Dim Part As Object

Dim boolstatus As Boolean

Dim longstatus As Long, longwarnings As Long

Dim ConfigName As String

Dim DrawingName As String

Dim GetPathName() As String

Sub main()

Set swApp = _

Application.SldWorks

Set Part = swApp.ActiveDoc

ConfigName = swApp.GetActiveConfigurationName(Part.GetPathName)

DrawingName = "W:\SolidWorks\" + ConfigName + ".SLDDRW"

Set Part = swApp.OpenDoc6(DrawingName, swDocDRAWING, 0, "", longstatus, longwarnings)

If Part Is Nothing Then

    DrawingName = "W:\SolidWorks\" + ConfigName + ".SLDDRW.lnk"

    Set Part = swApp.OpenDoc6(DrawingName, swDocDRAWING, 0, "", longstatus, longwarnings)

    End If

Set Part = swApp.ActiveDoc

End Sub

My thoughts are that Solidworks is looking for a Drawing file but doesn't catch it since the file type is a shortcut (.lnk). Do I need to use a different OpenDoc6 Document type? Is this type of action even possible?

Any help is greatly appreciated. Thank you.