What is an API?
An Application Programming Interface (API) is a shared boundary provided by a software to facilitate communication. In the case of a CAD system, it is a way to interact with the software and CAD files with another program. Companies, such as Dassualt; the makers of Solidworks, provide these APIs as a consistent entry point. An API is like supervised access to the back room. It won’t let you in anywhere you shouldn’t be, and won’t let you break anything important, but you can still see how the sausage is made. APIs in CAD programs open up new possibilities in how you interact with the program. From reading data to automating design, API’s are a powerful asset.
Ways to Interact with the API
In the case of Solidworks, there are three common ways to interact with the API.
Macro – A small program or script to automate a common task, usually launched by loading the program with the macro utility. Solidworks allows you to create macros by recording user actions as an easy jump off point. Useful for quick and small time saves. All macros are written in VB.Net, but no extra software is needed.
Add-in – An application that exists within the CAD program, usually launched by a custom menu button. Useful for adding functionality that needs to fit seamlessly into the design workflow. Add-ins can be written in either C# or VB.Net, but either way you’ll need your own development environment.
Stand Alone – An external application that can launch and interact with CAD programs from another window. Usually launched like any other desktop application, with a shortcut. Useful for applications where data is gathered from CAD, but used for purposes other than design. Stand Alone applications can be written in either C# or VB.Net like an add-in.
With three different ways to interact with the API, which one is best? The answer is, all of them. Each way to use the API is tailored to what it is being used for. Macros are perfect for a quick and dirty one time action. Add-ins extend the abilities of your CAD and make day to day tasks easier. Stand-Alone applications break your CAD free and open up options such as integrating into other software such as a CAM or ERP software. Each option has it’s pros and cons, and making the right choice comes down to the purpose of the application.
|Quick and Easy to implement, no additional tools required
|Difficult to scale
|Seamless integration, scales well
Best done in an IDE
|More flexible options for UI
Less dependent on a specific CAD application
|Less seamless interaction with the CAD application
What can be done with the API?
Short answer: Everything. In the case of Solidworks, almost any action that a user can take can also be done by the API. Anything from reading file properties, to creating features such as drawings. We can break down most actions into four categories:
Create – You can create new drawings, properties, features, and even files. Automating creation can save the overhead of setup, especially when setup protocols are well defined and consistent.
Delete – With the power to create, comes the power to destroy. Useful for cleaning up a mess, most items that can be created can also be removed.
Update – The downside of creating data is keeping it up to date. Out of date data is only slightly more useful than no data. Using the API to keep data up to date can save users from the purgatory that is data management.
Read – Reading data is perhaps the simplest action with an API, but can be important. The data that is locked away inside a CAD model can be useful in the rest of the manufacturing process. Questions like: what is the BOM, which parts are purchased, which parts require paint, can all be answered manually, but compiling data quickly is what a computer does best.
In the example below, I created an add-in called UnBender Pro, which automatically creates a flat model of a bent weldment. For this automation, I was able to use the API to read the definition of the weldment feature, the drawing that defined it, and any holes in the model. Using this information I was able to construct a new model with the same weldment definition, bends replaced with straight sections ( with a K factor adjustment), all at the click of a button. Previously, the user had been making spreadsheets to calculate the new hole positions, and manually making the flat part. A time heavy approach, and single mistake in calculation could have resulted in thousands of scrapped parts.
Design Automation in Practice
The difficulty comes in not the what, but the how. A computer doesn’t think the same way as a human. A program cannot look at a model and know instinctively how to select “the opposite side”, solving a problem with the API relies on the problem being well defined and predictable. In some cases, the user’s process might need to change to be more compatible with the software that is being created.
Is It Worth it?
Creating an application is an investment, whether it is your own time spent or you’ve hired a developer. Before starting any project, it is important to consider if it is an investment that will pay off. Automation software hits on three benefits:
Time Saved – In business, time is money, and time saved is money saved. The time saved could be engineer time, or it could be lead times.
Effort – Something less considered is the human impact of what is being automated. The task could be really draining, or unpleasant. Few engineers will tell you that they enjoy doing data entry. Removing the pain of the task might make them happier and more productive.
Cost of a mistake – In some cases it isn’t the task that is valuable in automating, but rather preventing any errors. Something that takes 5 minutes, could take a full day to fix or have a large monetary cost. Automating is worth it purely for risk mitigation.
The last point to consider is who will be making the application. Outsourcing a simple macro might be difficult, simply because the project is too small for a developer to take on. But trying to make a full-fledged add-in might be more effort than it’s worth if your software skills aren’t up for it.
Written By: Caden Armstrong. Caden is the owner of SmartBench Software, a company specializing in creating add-ins and software for the engineering industry. You can visit www.SmartBenchSoftware.com to learn more about his bespoke software services.