This SolidWorks API Fundamentals series will explain the technical details of working with SolidWorks API. This series will be running parallel to the more practical approach in SolidWorks API series. To get the quickest start to SolidWorks API, feel free to follow the other series. In this series, we will be taking things much more slowly and in depth, as each aspect will be explained in detail.
Before we go into the technical aspects of the SolidWorks API, I would like to give you an understanding of what SolidWorks API actually is, and what it is capable of, and why it is such a powerful tool.
What is SolidWorks API?
The term application programming interface (API), as the name suggests, refers to a set of interface that can be used to create program for the application. In the case of SolidWorks API, the application refers to SolidWorks. The interface, in respect to programming, refers to a whole set of objects and methods within the SolidWorks application. Users will be able to use this interface to create automation programs.
Before we go further, I would like to bring to attention about how software are made as this would be useful in understanding how SolidWorks API works. In every software, a source code has to be created that contains all of the objects and methods required to run each of the feature you can find in the SolidWorks UI. This source code, of course, is highly proprietary and an industrial secret. So now if the software would like to allow users to create their own custom programs in the application, developers would create what is known as an API that acts as a bridge. The API connects the users code to the highly secretive source code. Now that this bridge (API) exists, users can use all of the functions created by the software developers, without the developers worrying about the source code being exposed as illustrated in the image below.
Now that we understand what an API is, lets dive deeper into the interface topic. If we refer to the SolidWorks API Help, we can see listed is a huge list of interfaces. Each of these interface correspond to certain components of the SolidWorks application. I would like for you to take some time to explore the names of the interfaces in the help page before continuing this article.
Now if you have gone through all the name of the interfaces, you would have probably already notice that each interface correspond to some specific feature within SolidWorks. Knowing that, it is not hard for the average SolidWorks user to find the correct API to use. For example, if you would like to create a macro that can automate the sketching process, you would look for the ISketch interface. From there, the interface would expose the objects and methods the you can use in your macro. The topic for actually using these objects and methods will be explained in the next topic.
The Capabilities and Potential of SolidWorks API
There are three main programming languages that the SolidWorks API supports. These are Visual Basic Application programming language (VBA), C#, and C++. This gives us flexibility to use our preferred programming languages. However, if you are just starting out and do not know which language to use, I would highly recommend starting with VBA. Every installation of SolidWorks comes with Microsoft Visual Basic for Application (VBA), which is a software created by Microsoft that allows users to write programs in Windows. VBA can be accessed within SolidWorks by going to Tools>Macro>New. You can create entire programs using VBA as well as custom userforms (graphical user interfaces).
Although powerful in it’s own right, some users may find VBA to be limiting when creating much larger programs. In these situations, that is where C# and C++ would shine. Using these languages, users can use their preferred integrated development environments (IDEs) such as Microsoft Visual Studio, which boasts much more powerful features compared to VBA.
Now that we have the programming tools, the things that we can do using SolidWorks API is only limited to the interfaces provided by SolidWorks and also by our programming skills. And in hindsight, almost every feature and function within SolidWorks can be accessed by the SolidWorks API! So what this means is that anything you can do from your regular use of SolidWorks, you can do using the API.
SolidWorks API is not only limited to creating macros. Using SolidWorks API, users can modify how the SolidWorks application behaves and look through add-ins, or even create complete stand-alone applications that can utilize certain SolidWorks functions. The table below summarizes the differences in each approach. IME Technology has developed a custom add-in, IME InterX, using SolidWorks API, to provide our customers with powerful automation tools.
Summary
This concludes the introduction to SolidWorks API, where I hope that you have a clearer view of SolidWorks API and the possibilities that can achieved using it. In the next article in this series, I will explain about variables in VBA.