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:

  1. Control flow basics explains variables, conditions, loops and subprograms with a simple made-up language. Nothing here depends on a specific control.
  2. 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.
  3. 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.