A CNC macro is only useful if you can trust it. The way to get that trust is straightforward: write the logic, test it in a simulator, then take the same program to the machine and prove it out.
The software is for training and simulation only. Yes, programs and macros you write and test in a MacroMill simulator can be saved or exported and run on a real CNC machine. As with any new program, prove it out first with single block, reduced rapids and a dry run before you cut.
The language itself — variables, IF/GOTO, WHILE loops and G65 calls — is covered in the practical guide to FANUC Custom Macro B. This post is about the habit that makes that language useful, with a short rectangular pocket example you can step through.
Why write a macro instead of a fixed program
A fixed G-code program is a list of moves for one size. Change the pocket length, the depth or the tool, and you are editing lines, or writing the program again. A Custom Macro B program takes those values as inputs, checks them, and calculates the path.
That is worth doing when the same method will be used on more than one size, when a loop is cleaner than a long copied pattern, or when a bad input should stop the program before it cuts. For shop-floor examples, see What problems do CNC macros solve? and Unlock CNC macros productivity on the shop floor.
A short example: a rectangular pocket
The calling program sets a tool, then G65 passes a centre, a final depth, the pocket length and width, a depth per pass, a tool diameter, a stepover, a clearance height and a feed. The macro checks the required inputs, then uses one WHILE loop for depth and a second WHILE loop to mill across the pocket in steps.
The figures are metric training values, not a job setup. With a centre at X0 Y0, an 80 mm by 50 mm pocket, a 12 mm tool and a 6 mm stepover, the tool-centre path should stay inside the pocket by one tool radius, and the last pass should finish on the far edge.
O8010 (RECTANGULAR POCKET CALL)
G90 G54 G17 G21 G40 G49 G80
T1 M06
G00 X0. Y0.
G43 Z50. H01
S2000 M03
G65 P8011 X0. Y0. Z-8. I80. J50. K2. D12. W6. R2. F200.
G00 Z50.
M05
M30
O8011 (RECTANGULAR POCKET MACRO)
(X=#24 CENTRE X)
(Y=#25 CENTRE Y)
(Z=#26 FINAL DEPTH)
(I=#4 POCKET LENGTH X)
(J=#5 POCKET WIDTH Y)
(K=#6 DEPTH PER PASS)
(D=#7 TOOL DIAMETER)
(W=#23 STEPOVER)
(R=#18 CLEARANCE HEIGHT)
(F=#9 FEED)
IF[#24 EQ #0]GOTO900
IF[#25 EQ #0]GOTO900
IF[#26 EQ #0]GOTO900
IF[#26 GE 0]GOTO900
IF[#4 EQ #0]GOTO900
IF[#5 EQ #0]GOTO900
IF[#6 EQ #0]GOTO900
IF[#7 EQ #0]GOTO900
IF[#23 EQ #0]GOTO900
IF[#18 EQ #0]GOTO900
IF[#9 EQ #0]GOTO900
IF[#4 LE 0]GOTO900
IF[#5 LE 0]GOTO900
IF[#6 LE 0]GOTO900
IF[#7 LE 0]GOTO900
IF[#23 LE 0]GOTO900
IF[#18 LE 0]GOTO900
IF[#9 LE 0]GOTO900
IF[#4 LE #7]GOTO900
IF[#5 LE #7]GOTO900
IF[#23 GE #7]GOTO900
#27=#7/2.
#31=[#4/2.]-#27
#32=[#5/2.]-#27
#28=#24-#31
#29=#25-#32
#8=#24+#31
#10=#25+#32
#30=0
WHILE[#30 GT #26]DO1
#30=#30-#6
IF[#30 GE #26]GOTO10
#30=#26
N10
#33=#29
WHILE[#33 LE #10]DO2
G00 Z#18
G00 X#28 Y#33
G01 Z#30 F#9
G01 X#8 Y#33
#11=#33
#33=#33+#23
IF[#33 LE #10]GOTO20
IF[#11 EQ #10]GOTO20
#33=#10
N20
END2
G00 Z#18
END1
M99
N900
(INVALID POCKET INPUT - CHECK THE CALL)
M99;
The vacant tests come first, because a missing G65 argument is empty, not zero, and using it in arithmetic can alarm. X and Y can be zero, so a centre at X0. Y0. is valid as long as those letters are passed. The pocket must be larger than the tool, and the stepover must be smaller than the tool diameter. After each depth step, the macro clamps Z so it does not go past the final depth. After each stepover, it adds one last pass on the far edge if the step would have skipped it.
This is a teaching skeleton: a raster pocket, one tool, and no cutter compensation. Change I, J or Z in the G65 call and the same program should produce the new size. For the variable map, IF/GOTO and WHILE rules behind this, see the FANUC Macro B guide and How a FANUC macro WHILE loop works.
Test the macro in a MacroMill simulator
Load the caller and the macro into a MacroMill simulator and run it there first. Use single block so you can see each assignment, each test and each move. Watch the variable values as the loops count, and check the 2D and 3D toolpath graphs against the pocket you had in mind.
If a path overshoots the edge, a loop does not finish, or a vacant argument raises an alarm, you want to find that on the simulator. Then change one input at a time — the depth, the length, the stepover — and confirm the path still makes sense. That is the same habit described in Practise FANUC G-code on your PC first, applied here to macro logic.
The FANUC VMC Advanced Control Suite is the milling simulator with a FANUC 0i-MF Plus style control, and it is a solid place to practise this kind of pocket macro. For turning macros, use the FANUC 0i-TF Plus lathe simulator. The A-axis VMC simulator is a separate product for 4th-axis training, and VMC Pro is a separate product that adds a probing suite. Do not treat one as a substitute for another.
Yes, you can run it on your machine
Yes, you can run that macro on a real CNC machine. Save or export the programs from the MacroMill simulator, load them onto your FANUC control the way you normally would, and prove them out with single block, reduced rapids and a dry run before you cut.
The simulator is for training and simulation. It does not replace a check of your own tooling, offsets, clearances, spindle speeds and feeds, and it does not replace the Custom Macro B manual for your control. Addresses and features can vary between FANUC series, so confirm the program on your own machine before you cut metal.
How else MacroMill can help
If you already have a CAM program with a lot of repeated motion, MacroFusion is CNC macro automation software that helps turn suitable repetitive CAM-generated G-code into compact, variable-driven macro logic. It does not replace CAM, it does not convert every program, and it is not a machine simulator. Review the result, then test it and prove it out in the same way as any other macro.
For a structured path from these basics into fuller cycles and family-of-parts work, use CNC Automation Pro 2026. It is MacroMill’s training platform for CNC macro programming, with structured lessons, pre-written macros, video tutorials and a certification pathway. It starts with the fundamentals and builds toward reusable macro logic. MacroFusion is a separate product and is not included in CNC Automation Pro.
For reference material, start with the free CNC macro resources page. When you want complete programs to study, open the CNC macro program library.
You can find the FANUC VMC Advanced Control Suite on macromillcnc.com. For tips and updates, join the MacroMill WhatsApp group: chat.whatsapp.com/Htae97asBiD14QiwMXjGJA.
The software is for training and simulation only. Yes, programs and macros you write and test in a MacroMill simulator can be saved or exported and run on a real CNC machine. As with any new program, prove it out first with single block, reduced rapids and a dry run before you cut. The code in this post is for learning and simulation. Addresses, tool offsets, clearances, spindle speeds and feeds must be confirmed against your machine, your tooling and your control’s Custom Macro B manual.
MacroMill

Leave a Reply