CADSharp Blog

Live API Training Class in Cleveland, OH in March

Blog 2.13.2015 1 Comment

Live SolidWorks API training

CADSharp is offering a 4-day live API training class titled “SolidWorks API Fundamentals” on March 30-April 2, 2015 in Cleveland, OH. Here’s what others have said about this class:

Great intro to SolidWorks API. Extremely helpful to have the object hierarchies explained versus having to try to reverse-engineer the steps from a zillion API Help entries. Also really enjoyed the personal flair that Keith brings to his craft. Keith has helped me achieve my 15-year-old goal of learning the SolidWorks API. I now feel like, given sufficient time, I could write any macro anybody would need!

Jason P.,

I used my new API skills in combination with DriveWorks a couple of weeks ago. I am amazed at how much easier it is now that I understand the API Help and API object model. Loved the interaction between peers and instructor.

Crystal Y.,

Why You Should Attend

<> Beginner-friendly. No previous programming experience required.

<> Small class size (5 attendees max) allows for excellent teacher-student interaction.

<> Complimentary one-year Premium membership to is included.

<> Content is designed by the industry’s leading SolidWorks API trainer, Keith Rice, to make you proficient in SolidWorks API fundamentals quickly and without frustration.

Course Contents and Objective

Download an outline of the course here.

This course emphasizes the three fundamentals skills of SolidWorks API programming: 1) Programming using Visual Basic Applications, 2) Using the API Help, 3) Understanding the SolidWorks API Object Model. After the course, students should feel comfortable researching API calls and using those calls to create macros from scratch.

Major topics include: VBA programming essentials, macro recorder, API Help, SolidWorks API object model, opening and saving documents, configurations, custom properties, selection handling, system and document options, sketch creation, feature creation, feature traversal, feature editing, geometry and topology traversal, and more (if time allows).

The speed and contents of the course will be adjusted on the fly according to the attendees current skill level and automation needs. Most of the content in the last day is chosen by attendees.


999 USD per person

Invoices may be paid by check, wire transfer, or credit card. If by credit card, an additional 30 USD fee is included. Invoices will be sent out a week before the class starts.

Important: I do not provide training computers. I encourage you to bring a laptop. If you are unable to bring one, email me about rental options.

Dates and Times

March 30 – April 2, 2015

Training is from 8:00 AM to 5:00 PM with an hour break for lunch.


La Quinta Inn, 4222 W 150th St, Cleveland, OH 44135

La Quinta Inn is conveniently located near Cleveland Hopkins International Airport. Continental breakfast and airport shuttle are available to guests free of charge.

Cleveland has many great night attractions for you to enjoy, including the Golden Horseshoe Casino.


Registration is limited to the first 5 people. Email me to register.

I hope you can join me in Cleveland for a great time of learning! Let me know if you have ANY questions.


Want to keep up with future content, webinars, and special offers? Sign up for our newsletter.

Leave Comment

What’s New In The SolidWorks 2015 API

Blog 10.20.2014 No Comments

SolidWorks 2015

The SolidWorks 2015 API contains quite a few enhancements that I am excited to share with you. Here are some of the most significant:

  • Access scenes.
  • Insert a table-driven pattern feature.
  • Get or set the components and transforms for interferences.
  • Specify more document printing options.
  • Create and access local curve- and sketch-driven patterns.
  • Get type of body folder cut list.
  • Specify more options when mirroring components in an assembly.
  • Add a width mate to an assembly.
  • Specify whether to print a specified layer when printing a drawing document.
  • Get a feature’s folder.
  • Move a feature to another location in the FeatureManager design tree of a part or assembly.
  • Get all of the bodies that result from splitting a part.
  • Modify a split-body feature by changing its split bodies.
  • Specify more options when editing a mate in an assembly.
  • Support for intersect features.
  • Support for extracting Scanto3D information.
  • Specify whether to keep or delete bodies in a multibody part.
  • Divide a sketch segment into equally spaced sketch segments or points.
  • Get the display dimension object for a specified pattern property or a sketch relation.
  • Get the sketch segments that define the path of a structural member body.
  • Specify more properties when creating a weldment gusset.
  • Specify more properties when creating a structural member end cap.
  • Specify more properties when creating cosmetic threads.
  • Modify variable-pitch helix features.

Want to see the API interfaces and calls related to each of these topics? You need only open up the local API Help, go to the Index tab, and search for the “Release Notes” category. This will show all enhancements in SolidWorks 2015 SP0 in great detail.

As always, if you discover an area where the API is lacking, don’t be afraid to submit it to the SolidWorks API support team.


Want to keep up with future content, webinars, and special offers? Sign up for our newsletter.

Leave Comment

Tips for Finding and Organizing Code Snippets

Blog 7.9.2014 5 Comments

If you’re even the least bit serious about SolidWorks API programming, then you need to have a game plan for efficiently doing each of these:

  • Finding code for use in a macro you are currently writing or plan to write
  • Organizing code so it can be easily found and re-used

Tips for Finding SolidWorks API Code

For example, let’s pretend that we want to learn how to change the active configuration of every component in an assembly. Here are a few avenues we might explore for finding such code (in rough order):

1. Record the action with the macro recorder and then study the code. In this particular case, the best we can do is record ourselves changing the configuration. There’s no way to record performing this task on every component in an assembly.

2. Look in the API Help for an example. This is where I usually start. Unless you’re researching something obscure, the API Help may very well have something similar to what you need. In our case, we might try looking under “Components –> Traverse” and “Assemblies –> components”. Both yield some fruit, but the latter in particular will take you to a list including IAssemblyDoc::GetComponents, which is the ideal method to use in this situation. Since this is such a common method, there are several examples of its usage, though these examples are far more complex than we really need.

3. Search on Over the years I’ve amassed a pretty formidable code library, I am not shy to admit. While only Premium members have full access, it is often-times useful to use the search field at the bottom of each page to search for a particular API call. This will usually bring up macros from the macro library. For example, if you search for “GetComponents” than you’ll be taken to a list of results including “Run code on every part in an assembly”. Unlike the examples in the API Help, I tend to keep my examples as simple and focused as possible, making them much more snippable (yes, I just coined that word).

4. Look on the SolidWorks API forums. This is usually my last resort, but it is worthwhile nonetheless. The topics covered by inquiring minds over the years are quite substantive, including many obscure topics not covered in the API Help. The challenge here is mostly figuring our what keywords to type in to ensure good results. Don’t be surprised if takes you a while to dig through the results. To ensure that you’re only relevant results, click the “Only for API” option before searching.

5. Search on Google. I almost never do this, because most results take you to the forums (which is easier to search within the forums’ search tool) or the online API Help (which is usually harder to search than the local API Help). Nevertheless, there’s a plethora formerly-active forums and API enthusiast websites tucked away in the omnipotent Google cache that might yield a gem of information.

Tips for Storing and Organizing SolidWorks API Code

Once you’ve learned how to change every assembly component’s active configuration, a wise move is to keep that code in an easily accessible place for later use. If you neglect to do this, then the next time you need that code, not only do you have to dig for it in any existing macro but you have to spend time extracting the relevant code from the irrelevant code. Spare yourself the tedium and store your code in a single, accessible location:

1. One large macro. Each code snippet should be in its own module, or at least its own function or sub-procedure. The advantage is that you can quickly test your code since it’s already in .swp form. The disadvantage is that you need SolidWorks open to in order to look at the code, making it more tedious to reference, especially if you’re working in .NET. I don’t recommend this approach, though a lot of people use it.

2. Word document. Certainly the simplest solution. Just make sure your document is backed up.

3. Evernote. This is my personal favorite. I use Evernote for far more than just API code, because it’s such a useful tool for organizing any information you need to access quickly. You can create a separate note for each snippet, and then tag them with “API”. Since the local Evernote client syncs with your online account, you’re data is safe and accessible from anywhere. Oh, and it’s free unless you need to upload more than 60 MB per month.

4. Code snippets feature in Visual Studio (.NET only). This is a little-known feature within the Visual Studio environment. Even the snippets can be accessed very quickly, they are stored locally, which means a lot of data down the drain if your hard-drive crashes.

5. I have never used this, but it seems like a good alternative to Visual Studio’s built-in code snippet manager. This will also work with VBA code. If I weren’t already using Evernote I might give this a try.

Additional Advice for Code Snippet Storage

Finally, let me offer two pieces of advice for those storing code snippets, regardless of location:

—Include comments in your code snippets. Yes, I know, documenting what your code does seems annoying in the moment, but 6 months later you’ll thank yourself for it.

—All but the simplest snippets should be stored as complete, self-contained, fully-functioning programs. Some might say, then, that we’re no longer talking about snippets at all, and perhaps that is true. But I have found that unless you work with the API regularly, it is easy to forget what prerequisite code is necessary for a snippet to work correctly. Let’s consider our earlier example. Here’s what a complete program changing every component’s active configuration looks like:

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim swComp As SldWorks.Component2
Dim i As Integer
Dim vComps As Variant
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swAssy = swModel
    vComps = swAssy.GetComponents(False)
    For i = 0 To UBound(vComps)
        Set swComp = vComps(i)
        swComp.ReferencedConfiguration = "Test"
    Next i
End Sub

This takes up quite a few lines. So you might be tempted to store a truncated, incomplete instead:

vComps = swAssy.GetComponents(False)
For i = 0 To UBound(vComps)
    Set swComp = vComps(i)
    swComp.ReferencedConfiguration = "Test"
Next i

Do not do this. You are defeating the purpose of using code snippets. The whole purpose is to prevent the need to re-research and re-write code, and yet that is invariably what will happen because you 1) forgot the context of this code (i.e., the data types involved and how to access those objects), 2) need to share the code with someone who doesn’t know the context, or 3) need to test the code (and in its current state, it will not compile).


There’s a lot of places to look in order to find the code you need, though starting with the macro recorder and local API Help is probably best. When it comes to storing code, Evernote is the clear winner, in my opinion. Always store code snippets as complete programs and always include helpful comments.

That ends our look at finding and storing SolidWorks API code. If you have any other tips or tricks you’d like to share, I’d love to hear about them! Please share below.

Want to hear about new videos, macros, webinars, live training events, and blog posts? Sign up for our newsletter.

Leave Comment