All tools

Macro B Playground

A FANUC-style macro interpreter in your browser. Run WHILE loops and IF GOTOs, step through line by line, watch every #variable change, and see the toolpath your logic actually produces — no machine, no risk.

Macro program

Runs entirely in your browser — nothing is sent anywhere, and no machine is attached.

Variable watch

Run or Step to watch variables fill in.

Toolpath (XY view)

solid = feed · dashed = rapid
Motion (G0–G3) shows up here as the program runs

Execution log

Assignments and jumps show up here as they execute.

The hardest part of macros is not the syntax

It's that on a real control you debug them one alarm at a time, with a part in the vise and a boss watching the spindle hours. A WHILE loop that never terminates, a GOTO to a sequence number that isn't there, an indirect write that lands in the wrong variable range — on the machine each of these costs you a setup; here they cost you a Step click. That's the whole idea of this playground: get the logic right where mistakes are free, then carry the macro to the control.

The same variables you're watching in the table are the ones that make macros valuable beyond programming tricks — probing cycles write measurement results into them, and part counters live there too. I covered how to pull those out of the control automatically in reading FANUC macro variables from a PC. And once your macro runs, the next question is what it costs in spindle time — the G-code time auditor will tell you where the seconds go.

Frequently asked questions

What is Macro B?+

Macro B (custom macro) is FANUC's programming layer on top of plain G-code: variables (#1, #100, #500…), arithmetic, trig functions, conditionals (IF … GOTO, IF … THEN) and WHILE loops. It's what turns a fixed program into a parametric one — a single bolt-circle macro that drills any hole count on any diameter, or one pocket program that machines a whole part family from two size variables.

Which subset of Macro B does this playground support?+

Assignments (including indirect #[expr]), + − × ÷ and MOD with bracket grouping, SIN/COS/TAN/ATAN/SQRT/ABS/ROUND/FIX/FUP (trig in degrees, like the control), EQ/NE/GT/GE/LT/LE conditions, IF [..] GOTO n, IF [..] THEN, GOTO n, WHILE [..] DO m / END m, N numbers, comments, and G0/G1/G2/G3 motion in absolute (G90) coordinates. Not supported: G65 argument passing and local-variable scoping, canned cycles (G81 etc.), G91 incremental mode, tool/work offsets, and control-specific system variables — so treat it as a logic sandbox, not a verifier.

Why do unset variables read as 0 here?+

On a real FANUC control an unset common variable is 'vacant' (#0, null), and null behaves differently from zero in comparisons — a classic source of subtle macro bugs. This playground simplifies that: any variable you haven't written reads as 0. It keeps experiments predictable, but remember the real control is pickier about vacant variables.

Is it safe to paste macros from production here?+

Yes. Everything runs in a JavaScript interpreter inside your browser tab — nothing is uploaded, stored, or sent to any server, and there is no machine on the other end. The 'toolpath' is just a drawing. The worst thing a pasted macro can do here is hit the 100,000-step limit and stop with an infinite-loop error.

Where can I learn more about macro variables?+

Start with your control's Custom Macro chapter (FANUC's Operator's Manual covers variable ranges, which ones survive power-off, and G65 argument mapping). The #500-range variables you experiment with here are the same ones probing cycles and part counters write on real machines — I've written about reading those from a PC over FOCAS, which turns macro variables into free process data.

Wrestling a part-family macro or probing routine?

CNC programming and process automation — that's my day job.

Get in touch
Home
Blog
Tools
Email
LinkedIn
Résumé