Macro programming: variables, conditions and loops in NC code
Macro programming for machinists: control flow explained in plain language, the parallels to programming languages like Python, and control-specific guides starting with Fanuc Macro B.
A normal NC program is a fixed list of moves. A macro program can calculate, compare values and decide what to do next. With it you can write one program for a whole family of parts, build your own cycles, read tool offsets and positions from the control, or stop the machine with a clear message when something is wrong.
The series is split into three steps:
- Control flow basics explains variables, conditions, loops and subprograms with a simple made-up language. Nothing here depends on a specific control.
- Macros and computer code puts NC macros next to Python. If you have ever seen a few lines of code, this shows you how much you already know.
- The control-specific guides show the real syntax. The first one covers Fanuc Macro B. Guides for other controls will follow.
You do not need any programming background. If you can read a G-code program, you can follow along.
Control flow basics
Variables, conditions, IF/ELSE, loops and subprograms explained for machinists with a simple made-up language, independent of any CNC control.
Macros and computer code
Variables, conditions, loops and subprograms in Python and in NC macro syntax side by side, with the pitfalls that catch machinists: degrees vs. radians, brackets, rounding.
Fanuc Macro B
Fanuc Custom Macro B for machinists: variable types, calculations, IF and WHILE, macro calls with G65 and G66, argument letters, system variables and a complete bolt circle cycle.