Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

SolidWorks API

Status
Not open for further replies.

rgrayclamps

Mechanical
Aug 6, 2004
376
I have experirence in both SolidWorks (2004 sp4.0) and VB.net, But I never tried SolidWorks API. Could someone shed some light on it? For example, how do I launch and open a SolidWorks document? I copied the following codes from a SolidWorks Journal file, but it does not work in VB.net.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim FeatureData As Object
Dim Feature As Object
Dim Component As Object

swApp = Application.SldWorks

Part = swApp.OpenDoc6("N:\New Vault\_Checkin\P-00000484.SLDDRW", 3, 0, "", longstatus, longwarnings)
Part = swApp.ActivateDoc ("P-00000484 - Sheet1")
End Sub
 
Replies continue below

Recommended for you

For starters, you are missing "Set" statements when designating object variables.

Set swApp = Application.SldWorks

Set Part = swApp.OpenDoc6("N:\New Vault\_Checkin\P-00000484.SLDDRW", 3, 0, "", longstatus, longwarnings)
Set Part = swApp.ActivateDoc ("P-00000484 - Sheet1")
 
But, "Set" statements are not necessary in VB.

Thanks,

Alex
 
And yet, this is often a source of failure for many new programmers.

My SW API experience is entirely with VB6. Is VB.net different in this respect?
 
I am not sure if VB.net is different in this respect. How do you open a SolidWorks document using VB6.0 API?

Thanks,

Alex
 
Try this:

Code:
Set swApp = CreateObject("SldWorks.Application")

Set Part = swApp.OpenDoc6("N:\New Vault\_Checkin\P-00000484.SLDDRW", 3, 0, "", longstatus, longwarnings)

[bat]Due to illness, the part of The Tick will be played by... The Tick.[bat]
 
I tried your codes. But the second statement generated the following error:

"An unhandled exception of type 'System.Runtime.InteropServices. COMException' occurred in miscrosoft.visualbasic.dll

Additional information: Type mismatch"
 
Solidworks can not read VB.Net code. If you want to run your code inside Solidworks (for example as a macro) you have to use VB6.

If you want to use VB.Net, you have to create either a DLL, or an EXE file.

Use the wizard that Solidworks provides for creating .Net applications. Then use the Add-in in Solidworks to add your application to Solidworks. Be aware, creating an add-in is no trivial matter.

Good luck

jevakil@mapdi.com

One nuclear bomb can ruin your whole day.
 
i've done a lot of work with the API...perhaps you are missing just a few characters in the create object call:

try this:

Set swApp = CreateObject("SldWorks.Application.12")

you can leave the arguments to opendoc6 null if they give you trouble.
 
rgrayclamps,
What we do instead of creating an add-in is to make an executable from the VB code. Then we create a link to drive the executable from within SolidWorks.
For example:
Option Explicit

Dim swApp As Object
Dim Part As Object
Dim MyAppID, ReturnValue

Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
' This program runs when I pushed Ctrl F12

MyAppID = Shell("\\MyServer\Eng\Applications\SolidWorks\Executables\Titleblock.exe", 1)

End Sub


Bradley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor