Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Getting Started, Basics, SW API

Status
Not open for further replies.

seedie54

Automotive
Dec 16, 2001
6
0
0
AU
hello all,

Im looking to integrate Excel and Solidworks 2001. I am using Visual Basic 6.0. As a test, I tried the following code, to extract data from Solidworks, and display on the screen:

Sub Command1_Click()

Dim swApp As Object
Dim Part As Object
Dim Length As Double

Set swApp = CreateObject("SldWorks.Application")

SwApp.Visible = True
swApp.UserControl = True

Set Part = swApp.ActiveDoc

Set Length = Part.Parameter("Line1@Sketch1").SystemValue

MsgBox("Line1 in sketch1 is of length: " & length & ".")

End Sub

I did this in Visual Basic as a Standard EXE (on a button click), not as a Macro. Solidworks is open at the time, and the sketch active.

Do i have to use macros?? If i use VB6.0, do i have to declare functions from .dll's?? if so, how do i know which functions are in which .dll??

When compiling, VB didnt like the line "Set Length = ..."

Any assistance is greatly appreciated

API Beginner
 
Replies continue below

Recommended for you

I'm confused??

If your wanting to intergrate Excel into SW...Why are using VB?

In Fact Excel is already intergrated into SW. You can use Design Tables in SW parts and assemblies to get there. You can then use VBA to control those parts.

Plus you can take excel and make a spreadsheet that controls a SW part or assembly and it doesn't need to be embedded as a DT. See my website

Download ExcelVBAexample.zip

This will explain it better than I can write it.

If you are wanting to use dll's in your programs, your going to have to learn C++ I believe. I don't think VB can handle that.

I always record macro first, because I can usally get the proper API code required to do the job, but not always.

dsi is the best at answering these kind of Questions, but you may not hear from him till after the new year.

Hope that helps....? Scott Baugh, CSWP :)
George Koch Sons,LLC
Evansville, IN 47714
sjb@kochllc.com
 
Thanks for your rapid reply.

Im more concerned about taking values FROM SW, and importing TO excel. Since i started this thread, ive had some luck. I asked about VB, as i plan to have a stand-alone program, that will have its own user interface and work with both programs. My understanding is that macros dont allow much user interfacing (just running in the background)

Please excuse my ignorance, im VERY new to all this.

seedie54
 
The SystemValue property does not return an object, so you should not use the Set command.

Length = Part.Parameter("Line1@Sketch1").SystemValue

Don't forget that the SystemValue property returns a value of meters and Line1@Sketch1 should be the name of a dimension.


DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
What you want to do is write a comm add-in to solidworks - this will allow you to launch your application from a custom menu and/or toolbar. The only tricky part is to properly register the add-in so that it shows up the in tools-addins list without pointing to it manually (not a problem if you are writing a custom app for deployment to only a few users).
 
Status
Not open for further replies.
Back
Top