The Benefits of SOLIDWORKS API and SOLIDWORKS PDM API
The API for SOLIDWORKS and PDM can provide a huge number of optional benefits. This is a Q&A style article intending to walk the average person through the otherwise broad and complicated topic. I’ll start from the beginning by explaining what it is and provide some examples. Then move through to best use cases and suggestions for refining your need into a program. And if you need further help or suggestions, we have an experienced development team at CATI dedicated to creating custom applications for our customers.
What is SOLIDWORKS API and what can it do?
The SOLIDWORKS API, or Application Programming Interface, allows the automation of repetitive and tedious tasks within SOLIDWORKS. Custom applications using the SOLIDWORKS API can be as simple or as complex as desired, for instance, the API can be used to create simple macros. Macro’s, at their core, are just a preprogrammed sequence of events. Sequences of mouse clicks can be recorded and automatically inserted into a new macro by using the SOLIDWORKS macro recorder. Simply start the recorder and then perform the set of actions you’d like repeated. That will produce a very simple VBA macro that can be replayed at any time.
More functionality can then be added to a macro by editing it in the built-in VBA macro editor. All sorts of things can be added, including logic and intelligence, prompts to the user to send warnings and other information or to gather user input and selections. SOLIDWORKS Standard, Professional, and Premium all come with the ability to use, create, and modify macros.
It is also possible to create more complex applications by using C#, VB.net, or C++. These programming languages can be used to create custom add-ins and stand-alone applications that can launch and run SOLIDWORKS without a user’s interaction. See below for an example of a custom SOLIDWORKS add-in.
Ok, but can you be more specific about what the API can do?
The API can be used for anything that can save a designer time. It can also be used to accomplish things that normally could not be done by SOLIDWORKS. Such as inserting a user coordinate system at a specified X, Y, Z location or setting a file to automatically perform additional actions whenever the model is rebuilt, such as updating a general table. Other interesting ideas are adding a watermark or some visible label to a part model that cannot be deleted or removed. BOM tables can be exported to CSV or Excel. Custom properties can be populated from an Excel spreadsheet. And the list goes on.
It is important to note that SOLIDWORKS macros are based on VBA. This is the same language used by Excel. So, if you have ever made an Excel macro, the concept is the same in SOLIDWORKS. The main difference is that SOLIDWORKS has its own set of API calls (contained within a VBA reference library) that are used to interact with SOLIDWORKS, just as Excel has its own set of calls for interacting with spreadsheets.
Creating your program as an add-in instead of a macro can provide several benefits. For instance, they can be more stable, run faster, and be more reliably updated for new releases of SOLIDWORKS. Also, some things just work better as an add-in. The downside for many is that they take more programming experience to create, and the upfront effort is greater.
When should I consider turning to the SOLIDWORKS API for a solution?
The best use cases for creating an application using the SOLIDWORKS API are:
- Performing repetitive or tedious tasks.
- To perform an action or series of actions that are not available inside the SOLIDWORKS or PDM user interfaces.
- To save money by not having to manually do all of the above every day, one click at a time.
- Eliminating user error by automating tasks.
You said something about automating SOLIDWORKS PDM?
SOLIDWORKS PDM has its own API, and it’s just as powerful as the SOLIDWORKS API. The main difference is that there are no PDM macros. There are only add-ins and stand-alone applications. This means it must be programmed using C#, VB.net, or C++ (no VBA).
Since PDM is focused on file management, references, and tracking data, most custom applications for PDM also focus on those areas. They can manage file references, check things in and out of the vault, send custom notifications, and manipulate data card properties (and much more).
Another great thing, is that custom tasks can be set up for users to run on-demand or can trigger automatically on workflow transition (hopefully you are familiar with PDM workflows?).
Some add-ins are what I call ‘hybrid’ add-ins. These are add-ins in PDM that are designed to utilize both the PDM and SOLIDWORKS APIs. With these, PDM can automatically open files in SOLIDWORKS and perform specific actions. And it can use the information in PDM to determine which files to process. Information PDM can use include bills of materials, where used lists, file references and data card variables.
This section probably deserves its own blog… there is a lot I could write about here.
Ok, I have an idea! …now what?
Planning out your custom application is one of the most important steps – aside from actually getting it working! The first thing you need to do is describe what you want this program to do and write it down. Writing it down will force you to actually define it as opposed to just having an idea in your head that can change over time. It is very important to have a targeted goal in mind, even for the simplest of macros.
The 2nd thing you should do is build an outline. Ok, this is something you can maybe skip if you are just building something quickly or it’s only for yourself. Overall, it’s a little bit like writing a paper. Pick a topic, write a summary, then outline what the program should do. Use plain English and write down step-by-step what the application will do. This will also help when a year from now you’re trying to remember what this thing does.
Here is an example:
Summary: A SOLIDWORKS Add-in, that on the click of a button, will use the value of an existing custom property as the basis for a SQL query in a custom database. It will then use the returned string to automatically create 2 new custom properties in the currently open SOLIDWORKS part file.
Outline:
- The installed custom SOLIDWORKS add-in will have 1 icon.
- The add-in will only run on the currently open and active SOLIDWORKS part file.
- A configuration file will hold the custom property name, SQL query, and SQL connection string.
- The user must fill in the source custom property before running the add-in.
- Clicking the button will read the active document’s custom property value and run the SQL query.
- The values of 2 custom properties are filled in using the information returned by the SQL query.
- The custom properties will be created if they do not already exist.
In this case, the application was designed as a SOLIDWORKS add-in and would be written in C# programing language. This would allow for better handling of the SQL query than is available using VBA macros.
As you may have noticed, something like this could also be used for ERP integration. A full solution would need to be able to push information to the SQL database instead of (or in addition to) pulling from it.
But I’m not a programmer, can I just have someone make me whatever I want?
Yes! …provided it is possible. CATI has an amazing development staff that is ready to help. Our developers have been programming custom applications for decades. We would follow the same basic process I’ve already discussed, starting with what do you want to accomplish? Can any of it be done already with out-of-the-box functionality in SOLIDWORKS or PDM? Then we’ll help to refine your need and can get started building it for you.
Any recommendations on SOLIDWORKS API design?
The API is an amazing tool to help your designers and potentially other departments in your organization. The API is not intended to replace your designers, it is intended to increase their productivity. I usually recommend starting with one main goal for automation and then if you need more, to grow it from there. Many people try to put too much into an application at once and the scope can either grow out of control or never get finalized. It is often easier to pick a starting point, use it for a while to figure out if there are any other enhancements you would like made, and then do both the enhancements and additions at a later time.
I hope this has helped clear up what the API is and how it could benefit you. It has so much flexibility, if you are looking for more information, the online help files are available here: Welcome – 2022 – SOLIDWORKS API Help.
Regards,
Joe Phillips
Application Engineer II
Computer Aided Technology