SW API training course
SW API training course
(OP)
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.
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.






RE: SW API training course
http://www.cpuandsimplepdm.com
http://groups.yahoo.com/group/SolidWorks-API/
RE: SW API training course
RE: SW API training course
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.
RE: SW API training course
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
RE: SW API training course
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.
RE: SW API training course