I am trying to write a macro that will allow us to automatically open the
drawing file for a part or assembly we have open. I have most of the code
worked out, but I am not sure what the command is to get the current path
and file name of the active model in solidworks. I have done some VB
programming in the past, mostly in Excel. Unfortunately, I am not very
experienced with VB, especially object calls and working with APIs. Could
anyone help me? Thanks!!
Here is my code:
********************
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long
Dim Annotation As Object
Dim Gtol As Object
Dim DatumTag As Object
Dim FeatureData As Object
Dim Feature As Object
Dim Component As Object
Sub main()
path = "z:\models\MyPart.SLDPRT" 'get current model file and path WHAT
TO I PUT HERE TO GET CURRENT MODEL FILE AND PATH
path = StrConv(retval, 2) 'convert path string to all lowercase
If Right(path, 7) = ".sldprt" Then
path = Replace(Replace(path, ".sldprt", ".slddrw"), "\models\",
"\dwgs\") 'modify path to be path of corresponding slddrw file.
ElseIf Right(path, 7) = ".sldasm" Then
path = Replace(Replace(path, ".sldasm", ".slddrw"), "\models\",
"\dwgs\") 'modify path to be path of corresponding slddrw file.
Else
End Sub 'error, end macro
End If
Set Part = swApp.OpenDoc4(path, 2, 0, "", longstatus) 'Open drawing file
End Sub
>At my company, we have 1 folder on a server with our model files (sldprt,
>and sldasm) and another with our draiwng files (slddrw). One of these is
>z:\dwgs\ and the other is z:\models\. All our files use the part# as the
>file name.
>
>I am trying to write a macro that will allow us to automatically open the
>drawing file for a part or assembly we have open. I have most of the code
>worked out, but I am not sure what the command is to get the current path
>and file name of the active model in solidworks. I have done some VB
>programming in the past, mostly in Excel. Unfortunately, I am not very
>experienced with VB, especially object calls and working with APIs. Could
>anyone help me? Thanks!!
>
retval = ModelDoc.GetPathName ()
Markku Lehtola
CAD Instructor and Consultant
Done Training Center
Done Information Oy
www.projectcad.fi
retval = ModelDoc.GetPathName ()
Return:
(BSTR) retval
the full path name for this document, including the file
This is right out of the API help.
Mike Spens
"Arlin Sandbulte" <arlinsa...@hotmail.com> wrote in message
news:9fjt7e$bnj$1...@mtc1.mtcnet.net...
forgive me if the answer is obvious... like I said, I know BASIC, but not
VB.
"Mike Spens" <mi...@goengineer.com> wrote in message
news:eYsT6.41341$w4.10...@e420r-sjo3.usenetserver.com...
Set Doc=swApp.Activedoc()
retval=Doc.GetPathName()