Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Using Solidworks API sample programs in visual basic 1

Status
Not open for further replies.

ljavier34

Mechanical
Dec 2, 2005
13
I'm not familiar with visual basic...However, all I'm trying to do is use one of the sample programs in the Solidworks API for visual basics but I can't do it. It seems to compile just fine, but nothing happens, I don't know if I need to set something...I'm all confused...If any of you have any ideas please help me out...

 
Replies continue below

Recommended for you

I'm lost .........

"use one of the sample programs in the Solidworks API for visual basics"

What exactly are you trying to do? and what have you included the VB app?

Remember...
[navy]"If you don't use your head,[/navy] [idea]
[navy]your going to have to use your feet."[/navy]
 
Yes, please state which example you were trying to run and where you got it.

 
In solidworks when you go to Help>HelpAPI and add-ins help topics, you'll get to the API help files...Under the context tab go to Solidworks API Help>Examples>Visual Basic Examples > Assemblies>GetMates and get entities...This is the sample file that I was trying to use, but it could be any of the files in there...I'm just trying to establish a connection between visual basics and solidworks...If you guys are at all familiar, please help me out...Thank you
 
ljavier34,

Since you are not familar with Visual Basic, you may also not be familar with early binding (the way object variables are declared). The example you choose (and probably many others require that you set up VB for early binding. If you do a search in API help on early binding you will find two hits that should help you: "Early Binding" and "Early and Late Binding". Essentially what you have to do in VB is from the menu select Project, References. The References dialog will appear. From the list check "SldWorks 200x Type Library" and "SolidWorks 200x Constant type library". If you are using SolidWorks 2004 check the "SolidWorks Constant type library" (No year in the name). Now run the example program. It should work. Write back and let me know.

Regards,

Regg
 
Regg,

I tried what you suggested and it still doesn't work...It might be that I'm not putting the code in the right place in visual basic. When I go in, I choose standard EXE for project type, I then double click in the form and paste the code from solidworks, I then click start and nothing happens, no errors, nothing...I've been looking for online tutorials and they all seem to point in this direction for writing the code....Am I doing this right?

Thank for your help...

Javier
 
Javier,

You should really be running the example code from the VBA editor in SolidWorks. However, to run the code from VB, you must not paste the code into a form. You must remove the form and insert a module. Paste the code into the module, set your references and then change the line of code that reads:

Set swApp = Application.SldWorks

to

Set swApp = CreateObject("SldWorks.Application")

Now run the code. It should work. I just used your example code and followed the steps I described and it ran perfectly.

Having struggled with all this API stuff when I first began, I should have looked more closely at the example code. For that I say, I am sorry. I would have set you on a better course if I would have taken the time the first time.

Regards,

Regg
 
Regg,

What type of output did you get? I guess I still don't get anything or I am not clear where to look...I'll keep trying...but anyways thanks for all your help...I'm sure going in a better track now...
 
javier,

From the VB menu select View, Immediate Window. I do not have the example code up right now but you should see some debug.print statements. That indicates that output goes to the immediate window. Anytime you see this statement in the examples, look for the output to be there. Funny, when I ran the program last night, the immediate window automatically opened for me. Maybe because I use it myself for debugging my programs. I am still learning too.

Regards,

Regg
 
Regg,

Thank you so much...It finally worked...

Javier B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor