CATIA Macros

CATIA is a commercial CAD / CAM / CAE software developed by Dassault Systèmes. It runs on different OS platforms, and is typically used in mechanical engineering, design and systems engineering. CATIA is a high end 3 dimensional interactive tool that allows flexibility of using feature based and parametric design, and is used to create solid 3D models of objects. The heart of CATIA is the workbench, which is a specified environment consisting of a set of tools. This software from Dassault Systèmes is the world's leading solution for product design and experience, and it lets you design almost any product you can imagine. CATIA has had many versions since its inception, and Dassault continues to release upgraded versions.

CATIA Macros

Let us first understand what macros are. A macro is defined as a series of functions written in a scripting language that is executed en-bloc. Macros are used whenever a task needs to be performed repeatedly and involves a set series of steps. Macros automate tasks, save on time and reduce the possibility of human errors. 

CATIA is a vast software. It has such a huge amount of functionality that to really master the software, professional training from institutes is usually required. The application of automation in the design process is virtually unlimited. A few examples where automation in CATIA is useful includes creating, analyzing, measuring, modifying, translating, optimizing surfaces, solids, wireframes and other tasks like batch script for the conversion of CAT drawing files to PDF, import of points from an Excel spreadsheet to a 3D CAD model, export of data from CATIA model to a bill of material spreadsheet, etc. Because it is so complex, CATIA allows the use of macros to expand its capabilities by streamlining procedures. 

The  CATIA  object  is  usually  the  first  object  that  is  referenced  in  any CATIA macro. This object represents the CATIA application itself, from which the macro is run.  The CATIA object has many properties. Scripting languages such as VBScript, CATIAScript, VBA, etc. rely on objects and its properties. Most pieces of data you can access in CATIA are objects. In CATIA, documents, windows, viewers, cameras, parts, sketches, pads, even lines and curves, are represented as objects.

All the scripting languages (VBScript, CATScript and VBA) talk to CATIA through Dynamic Linked Libraries (DLL). A DLL file is a type of file that contains instructions that other programs can call upon to do certain things. This way, multiple programs can share the abilities programmed into a single file, and even do so simultaneously. Unlike executable programs, like those with the EXE file extension, DLL files can't be run directly but instead must be called upon by other code that is already running. However, DLLs are in the same format as exe files. In fact, some may even use the .exe file extension.

CATIA Macro Languages

CATIA allows the use of a few different scripting languages to write macros. Generally speaking, scripting languages are easier and faster to code than the structured, compiled languages like C, but they are a bit slower to run than the compiled languages. But naturally speed is not an issue as macros typically use only a few lines of code.


VBScript : VBScript from Microsoft is a scripting language that is a subset of Visual Basic Programming language. VBScript is essentially a trimmed version of Visual Basic (VB); all the elements of VBScript are present in VB, but some elements are not implemented in VBScript. As it is ordinary ASCII text, it is very easy to use VBScript. A simple Notepad suffices. It can be used on both Windows and UNIX versions of CATIA. The only disadvantage is that is a tad slow.

CATScript: CATScript is nothing but a portable version of VBScript developed by Dassault Systèmes. As you would expect, CATScript is similar to VBScript in many ways. It is a non-GUI sequential scripting language that can be coded using something as simple as Notepad. It has the same advantages and disadvantages as VBScript.

Visual Basic for Application (VBA): This is yet another subset of Visual Basic. Abbreviated as VBA, Visual Basic for Applications is a scripting language that is embedded in an individual Microsoft application such as Excel or Access. Using VBA you can create macros or small programs that perform tasks within the Microsoft application. VBA comes with its own editor, debugger and help object viewer. All versions of CATIA after V5R8 support macros developed using VBA.

Methods to create CATIA Macros

There are two basic methods whereby you can create macros in CATIA.

1. Macro recorder: CATIA allows you to capture mouse clicks. While this method is the simplest method of creating macros, it is error prone as it may add extra lines of code that are not necessary. Recorded macros do not contain any comments and the input parameters are not recorded. They are very simple and don’t contain any complex scripting commands like if statements or loops. CATIA experts generally do not recommend the use of recorded macros.

2. The second way - and the one most recommended - of writing a macro is to simply write custom code with the macro editor provided by CATIA. With an editor, you can write complex macros.

CATIA macros are run-in process, which means the CATIA program essentially freezes while the macro is running. The allocation memory is wiped clean after each run of the program.

CATIA stores the macros in macros libraries. They can be stored in one of the three locations – Folders (VBScript and CATScript macros), Project files or documents like CATParts, CATProducts and CATDrawings. CATIA allows using only one macro library at a time. While creating a new CATIA macro library, it is necessary to ensure that the folder or path locator already exists. 

As a good practice, it is recommended to be consistent with the CATIA macro order and format. It’s very useful to keep your code clean and tidy, especially if other programmers are going to work on it later.