From time to time I do presentations on the SolidWorks API and one that gets requested fairly often is the Beginner’s Guide To The API. I just presented this in Roanoke, VA at the Blue Ridge SolidWorks User’s Group headed up by Jeremy Marks. They were a good bunch of guys (although there was a University of North Carolina fan in attendance) and it seems like a well-run group. However, after risking my life to get there by driving through what seemed the rain-storm of the century on unfamiliar mountain highways with almost no visibility I have decided that in the future it might be safer for me to simply make the presentation available on my blog : )
Also, the SolidWorks Autonumbering Macro (w/ MS Access Database) that I usually show has been written up for ConnectPress with a link to download the Macro and Database. You can view that article here:
Disclaimer: This post isn’t directly API-related but using logic statements in SolidWorks equations is so useful that I decided to post it. Also, the syntax is in a kind of “techno-weenie-ese” so I thought I would help folks with the syntax.
The SolidWorks equation editor is a very useful, powerful and yet easy to use tool for building design intent into your SolidWorks model. However, most people don’t take full advantage of its power. In addition to support for constants, which are nice, the equation editor allows If…Then type logic statements. The idea is that you can set a dimension’s value to one of two values depending on the veracity of a logic statement pertaining to another/other dimension(s). Say what?….
Time for an example…
In spite of all their positive benefits, which are many, more than a few SolidWorks users look upon custom properties with the same disdain that a pre-schooler would have for green leafy vegetables. You can explain the benefits of custom properties, how they help you find things, how they lead to healthy drawing title blocks, how they improve PDM implementations, etc… until you are blue in the face and with some individuals you still won’t make a dent. There might be a change for a few days even a few weeks but inevitably you are back to files with no custom properties filled out.
In order to increase the life-expectancy of CAD administrators everywhere, I have posted a free .NET Add-In for SolidWorks that will “remind” your users to enter certain custom properties whenever they create a new file or save an existing one (after the initial save). The list of custom properties is configurable and
At the end of my last post on this topic, I promised you that I would share a “dirty secret” so I guess I now have to come clean. FYI – “Dirty secret” may have been a bit strong but it sounded cool (at least to me). Anyways, there is a difference between how SolidWorks handles CreateObject( ) and how MS Office products handle CreateObject( ). This is something to be aware of when automating across applications.
What is the difference? In a nutshell, calling CreateObject( ) on an MS Office application interface will always create a new instance of the application and then return a handle to that instance. Calling CreateObject( ) on the SldWorks.Application interface will only create a new instance of SolidWorks if one isn’t already running. This basically ensures that only one instance of SolidWorks at a time is ever automated by your Macro. This is a basic coding pattern called “the Singleton” and it prevents untold suffering and countless tears. SolidWorks is so kind to us and many of us didn’t even know it.
Below are two Macros continue
Last time I explained how the SolidWorks application object behaves differently depending on whether it is instantiated via CreateObject( ) or GetObject( ). So now you are probably thinking, “That’s it? That was too easy.” Well, I don’t want to be one to disappoint so I will let you in on the rest of the story including a dirty little secret.
So what else is there? The GetObject( ) call has another trick up its sleeve that I didn’t discuss last time. Taking a look at its Intellisense signature provides a clue as to what this is.
In the method signature you actually see two parameters, continue