Macro Programming (Parametric Programming)
Macro programming extends G-code with variables, arithmetic, conditional logic, loops and access to control data, so one program can adapt to part sizes, measurement results or machine states instead of using fixed values.
A macro program stores values in variables, calculates positions with arithmetic and trigonometric functions, branches with conditions and repeats sections in loops. It can also read and write system data such as offsets, current positions and tool data. Well-known implementations include FANUC Custom Macro B, which writes variables with the # character, Siemens SINUMERIK R parameters and user variables, and Heidenhain Q parameters.
Macros are used for families of similar parts, custom drilling or engraving cycles, probing routines that update offsets from measured results, part counting and tool-life logic, and automation tasks such as pallet and loading sequences. Machine builders and probe makers deliver many of their cycles as macros.
Because macros can change offsets and system variables, an error can move the machine unexpectedly or alter settings used by other programs. Good practice includes documenting variable use, protecting builder macros, keeping programs under version control and testing in simulation or a controlled prove-out. Macro syntax is specific to each control family, so macros are not portable between controls.
Key points
- Adds variables, arithmetic, conditions and loops to CNC programs
- Can read and write offsets, positions and other control data
- Used for part families, custom cycles, probing and automation logic
- Syntax is control-specific and errors can move the machine unexpectedly
Where AiVibe comes in
AiVibe designs and manufactures the AiAmbA AI Factory: edge devices plus AI agents that let people talk to CNC, PLC and robot controllers in plain language. Agents only propose changes, and a trained operator confirms each one.