How to Record a Macro in FreeCAD
Recording macros in FreeCAD allows you to automate repetitive 3D modeling tasks by capturing your graphical interface actions and translating them into executable Python code. This guide explains how to start macro recording, perform the intended operations, save the script, and run it later to reproduce your workflow instantly.
Step 1: Open FreeCAD and Prepare Your Workspace
- Launch FreeCAD and open an existing project or create a new document.
- Select the workbench you intend to work within (such as Part Design, Part, or Draft).
- Plan the actions you want to automate, as the recorder will capture every click, shape creation, and property modification while active.
Step 2: Start Macro Recording
- Navigate to the top menu and click on Macro.
- Select Macro recording... from the dropdown menu (or click the red circle icon on the Macro toolbar).
- In the dialog box that appears:
- Enter a name for your macro in the Macro name field.
- Choose a storage directory (the default FreeCAD macro folder is recommended).
- Click Record to begin tracking your actions. The recording icon in the status bar will indicate that recording is active.
Step 3: Perform the Tasks to Automate
Perform the sequence of actions you want to record directly in the 3D view or property editor. For example:
- Creating a primitive shape (box, cylinder, etc.).
- Applying fillets or chamfers.
- Modifying dimensions or placement properties.
Tip: Avoid unnecessary clicks, panning, or camera rotations, as these can clutter the generated script.
Step 4: Stop Recording
- Once your operations are complete, go back to the top menu.
- Click Macro and select Stop macro recording (or click the green stop square icon on the Macro toolbar).
- FreeCAD automatically generates and saves the Python script corresponding to your actions.
Step 5: Run Your Recorded Macro
- Open a new or existing document where you want to execute the sequence.
- Click Macro in the top menu and select Macros....
- In the list of available macros, select the file you created.
- Click the Execute button. FreeCAD will immediately rerun all the recorded commands.
Editing and Customizing Your Macro
To inspect or refine the generated code:
- Open the Macros... dialog window.
- Highlight your macro and click Edit.
- The script will open in the FreeCAD code editor, where you can modify parameter values, add loops, or insert conditional logic to make your automation more dynamic.