Blog - API Macros

API Macros

What Are Macros?

A MACRO (merge and correlate recorded output) is “anything more than a single command1” and a “rule or pattern that specifies how a certain input sequence should be mapped to an output sequence according to a defined procedure.4” Macro programs are “computer programs that capture the user’s actions as if it is recording the user.5” For example, macros can record mouse clicks, menu choices, and keystrokes.4

A macro may be made up of either a command and an option or commands, their options, and programming codes. Additional programming codes are included in macros to make it sure that macros work under any condition. For example, “^C^C^C” is used to cancel running AutoCAD commands, and “_” is used to make macros work with AutoCAD in any language.1 When being shared, some macros, such as those written using VBA (Visual Basic for Applications), require users to share source codes also.2 With the help of macros, users interact with the model environment through the API (application programming interface). Macros require some knowledge about software languages, but these programming languages are limited by what the command processor can handle. In macros, calls that are directed towards the API are like operations the users do in the UI. Macro programs can create, manipulate, plot, and print files as well as start programs or applications. For example, macro programs can use the mail function of the operating system to send files when such function is not supported by the interface of the CAD system. Macro programs are executed by a command processor in the system. In order to be effective and to serve their purpose, macro programs are expected to perform faster than users who enter commands in the UI.4,5

Why Write Macros?

The following are some reasons to write macros:4

  • Automation of common and repetitive tasks
  • Design optimization
  • Macros as bases for the development of special tools
  • For retrieving or exporting data from documents of the CAD solid modeler
  • Increase in productivity and standardization of procedures


The following are commonly used for writing macros, particularly macros for SolidWorks:4

  • VBA
  • Programming languages for writing standalone applications


Users get VBA along with their SolidWorks. Here, macros are saved as *.swp files. For them to create or edit SolidWorks macros, they first launch the VBA editor from within SolidWorks.4

For standalone applications, knowledge in Visual C++.Net, Visual Basic.Net, Visual C++, Visual Basic, and Visual Studio is required.4 It is easier to develop most macros in VBA than in VB.Net.2 Another way to develop macros is by the use of VSTA (Visual Studio Tools for Applications). In VSTA, users can store macros either externally or within a document. VSTA allows users to develop them using either Visual Basic.NET or C#.3

The result of automating common and repetitive tasks is a reduced time in doing processes.4 For example, a company need not do same tasks over and over again to create a standard component where formulas and parameters are used in the overall geometry of the component, if a macro program for doing it is already available.5

Macro Programs and API-Type of Programs

An API is used in designing solid modeling systems. It serves as the canvas for writing a macro. Based on a given parameter, the macro issues geometric instructions to the solid modeler, and then these geometric instructions are used in creating solid models of 3D designs.4

In SolidWorks, to create a macro program, the user clicks the start button in the macro toolbar, thereby ordering the CAD software to start recording. Then the user does operations that are being captured. Finally, the user clicks the stop button to tell the software to stop recording, and then the user saves the newly created macro.5

In 2D and 3D designs, macros automate design processes, while in 3D CAD packages, macros create and analyze design iterations.4

Macro programs are not necessarily the same with API programs. Sometimes, API-type of programs performs faster than macro programs. For example, creating thousands of lines, arcs, and dimensions would take a macro program some time to finish, but an API-type of program can do these tasks in seconds. API-type of programs uses the following languages: FORTRAN, Lisp, ADA, C, C++, or Java.5 For SolidWorks, its API uses VBA in developing procedural algorithms into the modeler.4 By using an API, entity databases can be accessed directly, which cannot be done by using macros. Scope and readability are limitations for macro programs, while the computer language that is being used is the only limitation for API-type of programs.5

API programming has its own advantages. These are the following:5

  • Ability to run as fast as the CAD system
  • Program sophistication


The following are SolidWorks API entities:4

  • Native geometrical entities
  • Native mathematical entities
  • User-defined entities


The following are list of SolidWorks API:4

  • EDrawings API
  • FeatureWorks API
  • PDMWorks API
  • PhotoWorks API
  • SolidWorks Routing API
  • SolidWorks API
  • SolidWorks Utilities API


The following are CAD packages that support API:4

  • Mechanical Desktop
  • SolidWorks
  • Unigraphics

1Ralph Grabowski. “TIPS: Macros.” Online posting. 5 Feb 2004. WorldCAD Access. 26 July 2010 <>.
2Ekins, Brian. Inventor® API: Taking the Step from VBA Macros to Add-Ins. Autodesk University, 2008. 26 July 2010 <>.
3Mason, Matt. “Revit 2009 API: VSTA: Here Comes the Neighborhood.” Online posting. 28 Feb 2008. CAD Application Development. 26 July 2010 <>.
4Srivastava, Rahul. Customization of CAD Modeling Software using Parametric Macros for Design of Machinable Artistic Surface Patterns. Patiala: Thapar University, 2009. 27 July 2010 <>.
5Schoonmaker, Stephen J. The CAD Guidebook: A Basic Manual for Understanding and Improving Computer-Aided Design. New York: Marcel Dekker, 2003.