CNC macros productivity comes from one simple idea: write the program once, prove it once, and let variables and logic handle every size and variant after that. Instead of copying, editing and re-proving a new G-code file for each job, a FANUC Custom Macro B program takes the dimensions as numbers and makes the decisions itself. This post shows where the time goes in a typical machine shop, how macros win it back, three short code examples, and where to start.
The hidden cost of rewriting programs
Most shops do not lose time cutting metal. They lose it around the cut. Every time a program is rewritten or hand-edited for a slightly different part, the same costs come back:
- Setup time: someone has to find the closest old program, copy it and change the numbers.
- Typos: one wrong digit in an X, Z or F word is all it takes. A missing minus sign on a depth is a classic.
- Crashes and scrap: an edited program is an unproven program, no matter how small the change.
- Prove-out: single block, dry run, first-off inspection. Again. For a part you have basically made before.
- Program clutter: dozens of near-identical files, and nobody is sure which one is the latest.
None of that adds value to the part. It is pure overhead, and it repeats on every job.
How CNC macros productivity shows up on the shop floor
Fanuc Macro B adds variables, math, decisions and loops to the control. That turns a fixed list of moves into a reusable tool. Here is how it pays off on the shop floor.
1. Family-of-parts programs
Flanges, spacers, shafts, plates: many parts differ only by a diameter, a length or a hole count. One parametric program covers the whole family. A new size means typing new values, not writing a new program, and the proven toolpath logic stays untouched. This is one of the clearest CNC macros productivity wins on a busy shop floor.
2. Reusable custom canned cycles with G65
A G65 call passes arguments into a macro, like a function call. Each letter lands in a local variable: X goes to #24, Y to #25, Z to #26, R to #18, H to #11, A to #1 and F to #9. Write a bolt hole circle once and it becomes your own canned cycle:
(CALL FROM ANY PROGRAM)G65 P9100 X0 Y0 R50. H6 A0 Z-15. F120.O9100 (BOLT HOLE CIRCLE - CUSTOM CYCLE)IF[#18 LE 0] GOTO91IF[#11 LT 1] GOTO92IF[#26 GE 0] GOTO93#30=0 (HOLE COUNTER)#31=360/#11 (ANGLE BETWEEN HOLES)WHILE[#30 LT #11] DO1#32=#1+#30*#31 (ANGLE OF THIS HOLE)G90 G98 G81 X[#24+#18*COS[#32]] Y[#25+#18*SIN[#32]] Z#26 R2. F#9#30=#30+1END1G80M99N91 #3000=1 (RADIUS R MUST BE POSITIVE)N92 #3000=2 (HOLE COUNT H MISSING)N93 #3000=3 (DEPTH Z MUST BE NEGATIVE)
Six holes on a 100 mm PCD today, eight holes on 140 mm tomorrow: change the G65 line, nothing else. The WHILE loop does the repetition and the trig does the math the operator used to do on a calculator. For more cycles in this style, see Combining Fanuc Macro B With Canned Cycles: 6 Worked Examples.
3. Logic that makes decisions
IF and GOTO let one program choose the right path. The operator sets one number, and the control picks the matching size, with a clear alarm if the number is wrong:
O1200 (FLANGE FAMILY - ONE PROGRAM)#100=2 (PART TYPE: 1, 2 OR 3)G90 G17 G21 G40 G49 G80G54T03 M06S1800 M03G43 H03 Z50.IF[#100 EQ 1] GOTO100IF[#100 EQ 2] GOTO200IF[#100 EQ 3] GOTO300#3000=10 (UNKNOWN PART TYPE IN #100)N100 G65 P9100 X0 Y0 R40. H4 A45. Z-12. F120.GOTO900N200 G65 P9100 X0 Y0 R50. H6 A0 Z-15. F120.GOTO900N300 G65 P9100 X0 Y0 R70. H8 A22.5 Z-18. F100.N900 G00 Z50.M05M30
Three parts, one program, one proven cycle. Adding a fourth size is two lines.
4. Error traps with #3000 alarms
Notice the checks at the top of O9100. Writing a value to #3000 stops the machine with your own alarm text. A positive depth, a zero radius or a missing hole count is caught before the spindle moves, not after the tool hits the vice. One good trap protects every job that ever calls that macro.
5. Probing and automatic offset updates
With a spindle probe, a macro can measure the part, compare it to nominal and write the result straight into a work offset or tool wear offset through system variables. No more measuring, walking to the control and typing an offset by hand. The program can also stop with a #3000 alarm if a result is out of tolerance, so a bad part never gets to the next operation.
6. Consistency across operators and shifts
When the logic lives in a proven macro, the day shift and the night shift run the same process. New operators enter a few values instead of editing toolpaths. The experience of your best programmer is built into the program and available on every shift. That consistency is a quiet but real part of CNC macros productivity.
7. Shorter edits at the control
Changing one G65 line or one variable is quick, easy to check and easy to undo. Scrolling through hundreds of blocks to change every X value is slow and error-prone. Smaller edits mean less risk, which means less prove-out time. That is CNC macros productivity in its simplest form.
Where to start with CNC macros productivity
- Find your most repeated job. The part family you edit most often is where macros pay back first.
- Turn the changing numbers into variables. Keep the proven toolpath and replace only the dimensions. Our post From Hard-Coded G-Code to a Parametric Program shows this step by step.
- Add #3000 checks from day one. Every argument a macro needs should be checked before it moves.
- Prove it in a simulator first. Step through the loop, watch the variables change and check the toolpath before it reaches a real machine.
- Build a small library. Bolt circles, pockets, slots and probing routines. Document each argument at the top of the macro.
- Combine with CAM. Let CAM do complex geometry and let macros handle sizes, positions, counts and checks. Read G-Code Is Not a Programming Language. Macros Make It One for how the two work together.
Macros are not just for milling flat parts either. The same WHILE loops drive rotary work, as shown in our 4th axis CNC simulator post.
Note: reference examples only. Check variable ranges, IF/WHILE syntax and G65 argument assignment against your control’s Custom Macro manual, and prove every macro out with single block and a dry run before cutting.
Tools to get you there faster
You can build CNC macros productivity on the machine, but a simulator is the safer place to practise the loops, G65 calls and alarms first.
- MacroFusion™: helps turn repetitive, hard-coded G-code into reusable, variable-driven macro logic. $99.99 until 30 November.
- CNC Automation Pro™ 2026: Macro B from beginner to advanced, including custom canned cycles, G65 arguments and #3000 alarms. $69.99.
- Free trial: practise macros in the MacroMill FANUC-style simulators before you buy.
- Join the MacroMill WhatsApp group for tips and updates: chat.whatsapp.com/Htae97asBiD14QiwMXjGJA
Frequently asked questions
Do macros replace CAM?
No. CAM is still best for complex 3D geometry. Macros add the logic around it: sizes, positions, counts, probing and safety checks.
Is Macro B available on my control?
Most modern Fanuc controls support Custom Macro B, but on some machines it is an option. Check your parameters or ask your machine builder.
What is the fastest way to see a productivity gain?
Pick the one part family you edit most, turn it into a parametric macro with #3000 checks, and prove it in a simulator. The time you used to spend on edits and prove-out is the first thing you get back.
MacroMill

Responses
[…] is how macros stop you rewriting the same program for every size, which we covered in Unlock CNC Macros Productivity on the Shop Floor — Write Once, Not Again. The same WHILE pattern also drives rotary work, as in our 4th axis CNC simulator post. […]
[…] A macro earns its place when a job repeats with different sizes, when a pattern would otherwise be copied by hand, or when the program should check an input before it cuts. For a wider list, see What problems do CNC macros solve?. Writing the logic once and changing the inputs is also the subject of Unlock CNC macros productivity on the shop floor. […]
[…] more on what macros are for, see What problems do CNC macros solve?, Unlock CNC macros productivity on the shop floor, From hard-coded G-code to a parametric program, G-code is not a programming language, Why CNC […]
[…] That is how a macro becomes reusable for any size: WHILE removes the repeated blocks, and IF handles the cases. For more on the idea, see the CNC macro programming guide and write once, not again. […]