Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help with solidworks API

77 views
Skip to first unread message

Arlin Sandbulte

unread,
Jun 5, 2001, 8:18:51 PM6/5/01
to
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!!

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

M.Lehtola

unread,
Jun 6, 2001, 6:33:44 AM6/6/01
to
On Tue, 5 Jun 2001 19:18:51 -0500, "Arlin Sandbulte"
<arlinsa...@hotmail.com> wrote:

>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

Mike Spens

unread,
Jun 6, 2001, 12:37:24 PM6/6/01
to
Syntax (OLE Automation)

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...

Arlin Sandbulte

unread,
Jun 6, 2001, 8:42:07 PM6/6/01
to
I tried this, but I get an error.... Object variable or With block variable
not set

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...

Martin Knoesel

unread,
Jun 7, 2001, 8:02:26 AM6/7/01
to
Assuming you have an active session of Solidworks called swApp launched:

Set Doc=swApp.Activedoc()
retval=Doc.GetPathName()

0 new messages