Design Automation with SolidWorks Macros
The new Design Automation (DA) tools for SolidWorks are wonderful. DriveWorks, TactonWorks, and a host of others all give you the power to drive SolidWorks models…within reason. However, there are times when you want more control than the tool is willing to give you. Recently, a client asked us to remove instances from a linear pattern through DriveWorks. We all know that it’s possible to do manually through SolidWorks, but to control it through DriveWorks required a SolidWorks macro.
Currently, DriveWorks only supports the use of VBA macros (.SWP files) in SolidWorks due to internal SolidWorks API issues that are outside the scope of this article. It’s easy enough to create a macro, put it in the same folder as a model, and give it the same name as the model, but with a .SWP extension (add the word DRAW at the end for macros on drawings). Place the subroutine “MAIN” in a module named “DriveWorks” and the subroutine will be automatically executed once DriveWorks is finished driving the clone. You can also put common macros (code that should be run for each model or drawing) in your content folder in later service packs of DriveWorks 6.
The tricky bit is interacting with the SolidWorks macro. If you’ve worked with DriveWorks, you’ll know that it is a push system, meaning that it performs its calculations before it ever opens SolidWorks. This means that DriveWorks automations cannot interact with SolidWorks unless you add code within the Design Master. But the issue of providing inputs to SolidWorks macros is a more common question.
In the case of the SolidWorks macro to remove instances from a linear pattern, the macro needs the list of instances as an input. The pattern would be driven by DriveWorks, but information about the pattern is needed by the macro in selecting the correct instance to delete. One great technique for passing this information is to put the inputs into SolidWorks custom properties. DriveWorks can easily drive custom property values with out-of-the-box rules and a SolidWorks macro can easily read custom property values with the GetCustomInfo method on the ModelDoc2 object.
So keep in mind that you may not be at the end of the line when you reach the limitations of your Design Automation system. SolidWorks macros are a great way to extend the capabilities of DA tools when you have a specific or tricky requirement. For now, don’t rule anything out. Dive into the API, or get in touch with us for some advice.
Tags: API, custom property, Design Automation, DriveWorks, SolidWorks, SolidWorks API, SolidWorks Macro, Tacton
Read more posts by Paul Gimbel

