Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

SW API training course

Status
Not open for further replies.

Jimijames

Mechanical
Jan 17, 2002
20
has anyone taken it? My company won't spring for the whole course (ROI blah, blah, blah), but I may have an opportunity to get the materials used in the course for self study.

So far I've taught myself the basics of VB/VBA (e.g. I've written a custom prop macro and designed a nice dialog to go with it, wrote a macro to fire up a drawing after inputing sheet size, scale, materials notes etc, and a macro to traverse an assembly and spit p/n's and qty's to an excel spreadsheet), but I'm always looking to learn more. Are the books/materials from the API class a good source for more advanced self teaching or is it more of a powerpoint presentation with no real content?

Thanks.
 
Replies continue below

Recommended for you

I'm in the same boat. I need to learn API, but company won't pay right now. Any info you have so I can learn on my own? TheTick has some good info, but the PowerPoint presen from didn't help me much.
 
Mostly, I learned by jumping into the deep end. Remember your programming basics: plan your processes (read: "flowcharts") and begin with the end in mind. Don't be shy about writing helper functions to simplify SW API calls.

It takes time to get comfortable with the SW object structure. Most confounding is the differentiation between the "ModelDoc" object and the "PartDoc", AssemblyDoc", and "DrawingDoc" sub-objects. Similarly, it helps to get comfortable with calling parent and child objects, such as getting a body or feature object from a part, getting a component from a selected face, or getting a part from a selected component.

When you define variables, use early binding. For instance, define your swApp as Sldworks.SldWorks instead of the generic Object. Make sure you incluse the SW type library "sldworks.tlb" in your references. To do this, from within your VB macro editor, go to "Tools --> References" and make sure you have "SldWorks 2003 Type Library"[/] checked.

Again, the most confounding thing about this is the ModelDoc/PartDoc/AssemblyDoc/DrawingDoc thing. Model files is best left defined as a generic object. I sometimes define "dummy" ModelDoc, PartDoc, AssemblyDoc and DrawingDoc objects to use to get the pop-up lists, and then replace that object with the file object.

[bat]All this machinery making modern music can still be open-hearted.[bat]
 
The help files can be tricky, especially if you dont have a lot of VB experience, or a little 'C' experience: the data types are written from a 'C' programmers point of view.

here's a 'translation' of the data types from SolidSpeakish to VBA:


BSTR

This is a String(NOT a fixed length string!). Used to hold names, etc.

Dim MyString as string
Dim MyString$


double

Double precision. Uses decimals. The most accurate available in VBA.

Dim MyDouble as double
Dim MyDouble#


single

Not even sure if solidworks uses this one; holds decial numbers like Double, but not as
high a range. If you're using a 64-bit processor, there is no extra overhead in
using the double type, so I think pretty much everyone uses double now.

Dim MySingle as single
Dim MySingle!



LONG

Long Integer. Holds Values in VBA that can be greater than 32565. Normally used to
pass values defined in SWConst.bas

Dim MyLong as long
Dim MyLong&

BOOL

Boolean . Boolean values, like True or false. Used a lot as return values to see
if a function completed successfully. You can actually use INTEGERS here, too,
because they are stored as integers anyway, so TRUE is the same value (False is
always ZERO)


Dim MyBool as boolean
Dim MyBool as integer



LPDISPATCH

This means OBJECT. Either dim a generic OBJECT. or dim a specific type of sw object:

Dim MyModel as Object
Dim MyModel as ModelDoc2



VARIANT

' in VBA, it can be *any* of the above types. And it WILL be if you dont specifially
DIM it as anything else. Normally used in SW to hold arrays. of other data types.

Dim MyVnt as variant
Dim MyVnt
 
Another caution about variants in VB:

If you have a variant retval that was returned from one function, and you want to use it in another function that requires a specific data type like Long, take the time to type in the conversion CLng(retval). Sometimes a variant just won't do in place of a specific data type.

[bat]All this machinery making modern music can still be open-hearted.[bat]
 
Thanks much. Anyone know of any good books or web sites on this subject?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor