13.12Macros

QW-Modeller and FreeCAD can be entirely controlled by Python scripts from the integrated python console, from macros or from any other external Python script. Macros are a very convenient way to create complex geometries in FreeCAD. There are possibilities of creating or modifying geometry, creating or modifying QW-Objects and modifying the representation of those objects in the 3D scene. Python scripting can also be used in macros, which provide an easy method to create custom commands.



More detailed information about macros is available in the FreeCAD help through Help®FreeCAD Help command from the main menu.



Macro Executing


The Execute macro dialogue can be invoked using Macro®Macros... command from the main menu. It allows managing your macros, deleting, editing and creating new ones from scratch. If you edit a macro, it will be opened in a text editor window where you can make changes to its code.



The macros location displays the path for the macro directory. Python files have a file extension of .py while FreeCAD macros (which are also Python files) use the file extension .FCMacro. The Macro facility of FreeCAD can also execute files with the extension .py.


If macro files are placed in the macro directory, they will be listed in the macro list. Selected macro file can be executed, edited or deleted and also new macro can be created using Create button.



Macro Creating


After clicking the Create button in the Execute macro dialogue, the following dialogue will appear:

 


After entering the macro file name, the macro text editor will be open.




Macro Recording


You can simply create macro by just recording the actions as you do them, then save that under a chosen name, and replay them whenever you want. Since macros are in reality a list of python commands, you can also edit them, and create very complex scripts.

After pressing the Macro®Macro recording... command from the main menu, you will be asked to enter a name to your macro, and then perform some actions.



When you are done, click the Macro®Stop macro recording command from the main menu, and your actions will be saved.

 

See Macro tutotrial example for more information.