Enumerations to save the world!

EmailFacebookGoogle+LinkedInTwitterShare

Enumerations are great little tools designed to make working with your API code easier. In SOLIDWORKS API, enumerations are often used to collect constants together in groups.

As an example, this line of code is perfectly acceptable:

swFeature.GetType = swSelBODYFEATURES

However if later you want to change the type of feature you are looking for you have to look up all of the constants “GetType” returns. This can take some time.

If you use enumerations, VBA’s IntelliSense provides you with a droplist to make selecting the proper constant name easier. Type the enumeration name, the period then…

droplist

Thus I am recommending the above code should have been written like this:

swFeature.GetType = swSelectType_e.swSelBODYFEATURES

It’s the same thing, just easier to work with. (Enumeration names can be found in the help file.)

ReturnValue

Once last super cool enumeration tip. Declare your variables using enumerations.

Continuing the above example, say you want to store the type of feature you found in a variable. If an enumeration is available, don’t simply declare the variable as a generic type, use the enumeration instead.

Dim intFeatureType As swSelectType_e

Now whenever you work with this variable, IntelliSense is there to help you along the way. Hit the equal sign and…

if
Better, faster, easier to read, more accurate code.