G-Code Is Not a Programming Language. Macros Make It One: My Journey From the First Macro to CAM + Macro B
Most CNC programs are not really programs. They are recordings. A long list of moves that tells the machine exactly where to go, one line at a time, the same way an operator would turn the handwheels. Change the part, and you record it all again.
That is the honest truth about plain G-code: it is a repetition of manual movements, not a full-fledged computer language. The moment you add macros, that changes. This post is about that change, what it did for me, and how you can start.
Why plain G-code is not a real language
A real programming language can store values, do math, make decisions and repeat work. Plain ISO G-code can do almost none of that. Every X, Y, Z and F is a fixed number typed into a line.
- No variables: a 100 mm part and a 120 mm part are two different programs.
- No decisions: the program cannot check a condition and choose a different path.
- No loops: five depth passes means the same block of code written five times.
- No awareness: it cannot read a probe result, a tool offset or a part counter.
Subprograms (M98) and canned cycles help a little, but they are still fixed playback. The control follows. It never thinks.
What Macro B adds
Fanuc Custom Macro B turns that playback into a real language, running directly on the control:
- Variables: #1–#33 local, #100–#199 common, #500–#999 persistent.
- Math: + − * /, SIN, COS, ATAN, SQRT, ROUND, FIX and more.
- Decisions: IF [condition] GOTO n and IF [condition] THEN.
- Loops: WHILE [condition] DO1 … END1.
- Arguments: G65 P9010 A.. B.. X.. Y.. passes values into a macro like a function call.
- System variables: read and write offsets, positions, modal states, and raise alarms with #3000.
With those six things, the machine stops being a playback device and becomes a computer that cuts metal.
From my first macro to today
My first macro was nothing special. A bolt hole circle. I was tired of calculating X and Y for every hole by hand, so I wrote a few lines with SIN and COS and a WHILE loop. Six holes, eight holes, twelve holes, any diameter: change two numbers and run.
That small program changed how I looked at every job. I started to see patterns everywhere. Families of parts that differ only by a few dimensions. Repeated operations that could be one cycle. Checks that a human forgot at 2 a.m. that the control could do every single time.
Then came probing macros that measured the part and updated the work offset. Tool-life counters stored in persistent variables. Safety checks that stopped the machine with a clear message instead of a crash. Custom cycles the operators could use without ever opening the code.
Today that journey is what MacroMill is built on: simulators, tools and training that help other programmers make the same jump, without learning it the hard way on a real machine.
The value it brings and why it makes you stand out
Many programmers can post a CAM file. Far fewer can make the control think. That is the gap macros fill, and it shows on the shop floor:
- Speed: a new size is a few numbers, not a new program.
- Fewer errors: one proven macro replaces dozens of hand-edited files.
- Safety: the program checks itself before it moves.
- Automation: probing, counters and offsets update without the operator touching a key.
- Career value: you become the person who solves problems, not just the one who loads programs.
The best of both: CAM + macros
This is not CAM versus macros. The strongest programmers combine them.
- CAM is the best tool for complex geometry: 3D surfaces, adaptive roughing, smooth finishing toolpaths.
- Macros are the best tool for logic: families of parts, part positions, probing, parametric features, safety checks and tool-life counters.
Let CAM generate the hard geometry once. Let a macro decide where, how often and under which conditions it runs. That combination gives you endless possibilities.
A short example: one CAM path, many parts
Say CAM gives you a finishing path for one part, saved as subprogram O2000 relative to that part’s zero. You have four parts on a fixture, 150 mm apart in X. The macro loops over the positions with a G52 local shift, counts tool use, and stops safely when the tool is due for a change.
O1000 (CAM FINISH x4 PARTS - MACRO DRIVER)
#100=4 (NUMBER OF PARTS)
#101=150.0 (PITCH IN X)
#102=0 (PART COUNTER)
#501=200 (TOOL LIFE LIMIT - SET ONCE)
IF[#500 LT #501] GOTO10
#3000=1 (T01 TOOL LIFE REACHED)
N10
G90 G17 G21 G40 G49 G80
G54
T01 M06
S8000 M03
G43 H01 Z50.0
WHILE[#102 LT #100] DO1
G52 X[#102*#101] Y0
M98 P2000 (CAM-GENERATED FINISH PATH)
#102=#102+1
#500=#500+1 (PERSISTENT TOOL-LIFE COUNT)
END1
G52 X0 Y0 (CANCEL LOCAL SHIFT)
G00 Z50.0
M05
M30
CAM did the geometry. The macro handles the number of parts, their positions and the tool life. Need six parts at 120 mm pitch? Change two numbers. Add a probing macro before the loop and each part can even get its own measured offset.
Note: reference example only. Check G52 and variable ranges against your control manual and machine builder’s documentation, and prove it out with single block and a dry run before cutting.
Where to begin learning macro programming
- Learn the variable types first. #1–#33 are local to a macro call, #100–#199 are common and usually clear at power off, #500–#999 are persistent and survive power off. Know which is which before you write anything.
- Learn #3000. #3000=1 (MESSAGE) stops the machine with your own alarm text. It is your most important safety tool.
- Start with a bolt hole circle. It uses variables, SIN/COS and a WHILE loop in about ten lines. Then try the parametric contour in our post From Hard-Coded G-Code to a Parametric Program.
- Test in a simulator, never first on the machine. Watch the variables change line by line. See FANUC CNC Simulators With Built-In Cycles and Simulate Before You Cut.
- Read the Custom Macro section of your Fanuc operator’s manual. It covers variables, operators, system variables and G65 argument assignment.
- Combine macros with canned cycles. Our post Combining Fanuc Macro B With Canned Cycles shows how.
- Build a personal library. Every macro you prove out goes in a folder with notes. In a year you will have your own toolbox of custom cycles.
Not sure why macros matter yet? Start with What Problems Do CNC Macros Solve?
Tools to practise with
- CNC Automation Pro™ 2026: Macro B from beginner to advanced, including custom canned cycles.
- MacroMill FANUC 0i-MF Plus VMC Simulator: Macro Lab and live CUSTOM MACRO variable screens.
- FANUC 0i-TF Plus Lathe Simulator and the All-In-One Bundle.
- MacroFusion™: helps turn repetitive CAM-generated G-code into reusable, variable-driven macro logic.
- Free: CNC lathe simulators and CNC macro resources.
Frequently asked questions
Do I still need CAM if I learn macros?
Yes. CAM is better for complex geometry. Macros add the logic around it. Together they are stronger than either alone.
Does my control support Macro B?
Most modern Fanuc controls do, but on some machines it is an option. Check your parameters or ask your machine builder.
How long does it take to learn?
You can write a useful bolt hole macro in a day. Real confidence comes after building and proving a handful of your own macros in a simulator.
MacroMill

Leave a Reply