×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

SolidWorks API

SolidWorks API

SolidWorks API

(OP)
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

RE: SolidWorks API

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")

RE: SolidWorks API

(OP)
But, "Set" statements are not necessary in VB.

Thanks,

Alex

RE: SolidWorks API

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?

RE: SolidWorks API

(OP)
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

RE: SolidWorks API

Try this:

CODE

Set swApp = CreateObject("SldWorks.Application")

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

Due to illness, the part of The Tick will be played by... The Tick.
http://www.EsoxRepublic.com

RE: SolidWorks API

(OP)
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"

RE: SolidWorks API

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.

RE: SolidWorks API

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.

RE: SolidWorks API

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources