Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

API problem in 2005?

Status
Not open for further replies.

engAlright

Mechanical
Jun 12, 2003
240
0
0
CA
Has anyone had any problems with the basic Solidworks objects in Solidworks 2005? My code includes the following lines in a sub (pretty standard stuff):

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

Debug.Print swModel.GetPathName


When I run the code I get a run-time error 91: "Object variable or with block variable not set" at the debug.print line above. The swmodel variable is also "nothing" at the point where the error occurs, even though Solidworks 2005 is running and I have a document open. I'm using VB6.

Any thoughts?
 
Replies continue below

Recommended for you

We are still on 2004 and Visual Basic .NET but maybe this is worth a shot. I use swModel = swApp.IActiveDoc2 instead of ActiveDoc.

BBJT CSWP
 
engAlright

When editing the macro, in the VB environment, go to Tools/References and check the box "sldworks 2005 type library". Otherwise the Dim command will not be recognized with this sintax.


Regards
 
All good suggestions however I still get the same error. "Sldworks 2005 type library" is already selected in references and IActiveDoc2 gave me the same error as ActiveDoc.

This piece of code is how most of the examples in the API help begin. I'm wondering why it won't work in Solidworks 2005.

Thanks!
 
I can't help you, engAlright. My API knowledge is little-to-none. But maybe your problem and this one of mine are similar.

System: Dell Precision 650—Intel Xeo @ 2.66 GHz with 1/2G RAM
OS: Windows 2000 SP3
Graphics: NVidia Quadro FX 500 128Mb (OpenGL set to Solidworks)
Version: Solidworks 2005, SP0.1
 
>>All good suggestions however I still get the same error. "Sldworks 2005 type library" is already
>> selected in references and IActiveDoc2 gave me the
>> same error as ActiveDoc.

Try a little voodoo here. Bring up the 'References' window again, select the SldWorks.tlb file, and "Browse" back to the file in your SWX install dir, and re-select it.
 
OK - dumb support questions, but...

Are you sure you have an open document? Also, are you running VBA (macro recorder) or VB/VB.NET?

Evan

Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...
 
I encountered the same problem with one of my macros (SW2005). I couldn't find a solution so, for now, I left it on hold. It's good to know that it's not me (or us), it's them!
 
A follow-up - the code I pasted before works OK in VBA, but does not work in VB6. The code halts at the "Set swApp = Application.SldWorks" line saying that an opject is required.

Haven't tried it on SP1.1 though...
 
TheTick is right. Your problem is that VB6 runs as a separate process, therefore, you need to use either:

set swApp=CreateObject("SldWorks.Application")
or
Set swApp=New SldWorks.SldWorks

VBA runs as an internal process to SW, so you can just use the

Set swApp=Application.SldWorks

Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...
 
Status
Not open for further replies.
Back
Top