|
NHCAD
Fun Projects in Mechanical Design & Custom Programming Lebanon, NH
CAD(Computer Design)
CNC / Steppers
J2ME Mobile Programs
1964 Oday Javelin
|
SolidWorks Macros & Examples
SolidWorks MACROS - Tutorial and Examples While SolidWorks offers a great degree of customization through API function calls, the only built in programming you can do is with macros. The other programming languages that you could use with SolidWorks are VBA, VB, and VC++ (Visual Basic for Applications as in Excel, Word, and Access, Visual Basic, and Visual C++). Unfortunately the other programming languages all require additional software that will cost more money. The purpose of this article is to explore macros specifically because they are included with SolidWorks and this article should not exclude anybody that has SolidWorks. It happened to me, and it probably happened to you too. You recorded a macro only to find that it did not play back properly – if at all. Your first mistake is using the built in macro recorder, it is pretty useless. It is OK for capturing some snippets of code and seeing what function is called. From there you can look up the function in the SolidWorks API help file and continue working on another program for instance. Do not underestimate the power of macros! They really are functional, you just need to know what their limitations and abilities are. Here a few things to keep in mind when writing macros:
When you write macros, you will have to find or acquire the following three resources:
The SolidWorks API help file is very useful. It makes a better reference than a beginner tutorial but contains some very useful information none the less. There are hundreds of functions listed in the API help file, you will have to refer to it and understand the format of it as your programs become more complicated. The Swconst.bas file is an ASCII file that you can open and view using any text editor like notepad. It is intended to be used with Visual Basic programs as an add-in module. The information inside it is necessary for writing macros too, but you will have edit and look up the values manually. |