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.
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.
FANUC provides several ranges of variables:
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
Use G65 P9001 to call macro O9001. Pass arguments directly:
O1000 (MAIN)
G90 G54 G00 X0 Y0
G65 P9001 A6.0 B75.0
...
Arguments map to macro variables: A→#1, B→#2, etc.
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)
You can assign macros to G-codes (on newer FANUC controls):
Read real-time machine state:
#5021 - Current X position#5022 - Current Y position#5023 - Current Z position#3000 - Generate alarm programmaticallyNext: Read our FANUC Alarm Troubleshooting Guide