Macros, API and Add-ins — A Complete Guide
Macro, API, or add-in? Which layer solves which job, which language to pick, and where to start — gathered on one page.
SolidWorks automation means handing repetitive CAD work to software through the SolidWorks API. It has three layers: VBA macros that can be recorded and live in a single file, the API itself where you address the object model directly, and C#/.NET add-ins that load into SolidWorks and run inside it. All three use the same API; what differs is where the code lives and how it is distributed.
Changing a dimension and updating the drawing, exporting hundreds of files to PDF, filling in custom property fields one at a time — all of it can be done by hand. Automation means having SolidWorks do the same work on command from code. The thing that carries that command is the SolidWorks API.
The API is the layer that lets you reach every object inside SolidWorks — application, document, feature, dimension, configuration — from code. Macros and add-ins both use this same layer; the difference is not API access but how the code is stored and shipped.
Start here
They are not alternatives to each other; you pick by the scale of the job.
| VBA Macro | C# / .NET Add-in | Python (COM) | |
|---|---|---|---|
| Where it runs | Inside SolidWorks, a .swp file | A DLL loaded into SolidWorks | Outside, as its own process |
| Installation | Hand over the file and run it | Needs registration and an installer | Python plus pywin32 |
| User interface | Simple form | CommandManager, PropertyManager tab | None, or your own |
| Use it when | One desk, quick job | Team-wide, versioned product | Batch work, data processing, integrations |
| Maintenance | Gets harder as files multiply | Version control and tests are possible | Easy at script level |
A practical rule: if the job stays on one person's desk and runs a few times a week, a macro is enough. Once the same job spreads across a team, needs a user interface, and has to be versioned, it is time to move to an add-in. If you will process data outside SolidWorks — generating hundreds of variants from an Excel list, say — Python is usually the shortest path.
Choosing a layer
The order matters: each step builds on the one before it.
The most direct gain is eliminating the repeated modelling of the same work. The second — often more valuable — gain is standardisation: when output naming, folder structure and revision numbering are part of the automation, the files that reach production no longer vary by whoever made them.
Scope and measurement
Language models can produce SolidWorks API code, but between the size of the API surface and the subtleties of the COM object lifecycle, that code often does not run unverified. The gain is in scaffolding and in searching documentation; the loss is in shipping unverified code to production.
The AI side
The first week of an automation project is decided by what you measure, not by which tool you pick. Measure the repeated work first, choose a pilot, then grow it in the field. Tool choice comes at the end of that order.
Method and architecture
A SolidWorks macro is a VBA program that runs inside SolidWorks and automates CAD work through the API. It can be recorded with the Macro Recorder or written by hand, lives in a single .swp file, and runs without any installation.
The SolidWorks API is the COM-based interface layer that lets you reach the SolidWorks object model from code. You start at the SldWorks.Application root and travel through ModelDoc2, PartDoc, AssemblyDoc and DrawingDoc to features, dimensions and configurations. Macros and add-ins both use this same API.
Both use the same API; the difference is distribution. A macro is a single file, needs no installation, and is fast for one user. An add-in is a DLL loaded into SolidWorks: it can create its own toolbar and PropertyManager tab, can be versioned, and is deployed team-wide through an installer.
VBA to begin with, because the Macro Recorder emits VBA directly and the object model you learn carries over to every other language. C# / .NET if you are building a product for a team. Python with pywin32 is usually the shortest path when you are processing data outside SolidWorks or doing batch work.
Through Tools → Macro → Run, selecting the .swp file. For macros you use often, Tools → Customize lets you add a toolbar button or assign a keyboard shortcut, so the macro runs in one click instead of being hunted for in a menu.
Three common causes: the recorded macro produced selection-based code and the object is no longer selected; ModelDoc2 was accessed with no open document; or the referenced feature has been renamed. The fix for all three is the same — reach objects by name or identity rather than by selection.