FANUC Macro B Programming: Custom Cycles & Variables

By Nishikant Xalxo | FANUC CNC Programmer | Updated: January 10, 2025 | 12 min read

After 6 years of writing macros for FANUC 0i-MF and 30i-B controls, I've learned that Macro B is the single most underutilized feature in most shops. It can reduce programming time by 70% and eliminate errors. Here's how to master it.

What is FANUC Macro B?

Macro B is FANUC's parametric programming language that lets you use variables, logic, and loops in G-code. Think of it as "programming within a program." Unlike standard G-code that's static, macros adapt to different part dimensions automatically.

System Variables (#100-#999)

FANUC provides several ranges of variables:

Real Example: Bolt Hole Circle Macro
O9001 (BOLT HOLE CIRCLE)
#100 = 4          ; Number of holes
#101 = 50.0       ; Radius from center
#102 = 0          ; Starting angle (degrees)
#103 = 360 / #100 ; Angle increment
#104 = 1          ; Counter

N10 WHILE [#104 LE #100] DO1
  #105 = #101 * COS[#102]
  #106 = #101 * SIN[#102]
  G81 X#105 Y#106 Z-10.0 R1.0 F15.0
  #102 = #102 + #103
  #104 = #104 + 1
END1
G80
M99

Calling Macros with G65

Use G65 P9001 to call macro O9001. Pass arguments directly:

Main Program:
O1000 (MAIN)
G90 G54 G00 X0 Y0
G65 P9001 A6.0 B75.0
...

Arguments map to macro variables: A→#1, B→#2, etc.

Conditional Statements

FANUC macros support IF-THEN-ELSE logic:

#100 = #504 (read current tool diameter)
IF [#100 LT 10.0] THEN #100 = 10.0
IF [#100 GT 25.0] GOTO 100
N50 G01 X#100 F20.0
...
N100 #3000 = 1 (TOOL TOO LARGE)

Custom G-Codes

You can assign macros to G-codes (on newer FANUC controls):

System Variables for Machine Data

Read real-time machine state:

About the Author: Nishikant Xalxo has written 200+ FANUC macros for aerospace parts. He built the SHADER7 macro calculator to help other machinists. Questions? Email: nxdecore@gmail.com

Next: Read our FANUC Alarm Troubleshooting Guide