Example program · Mill

Parametric Bolt Circle Macro (WHILE Loop) — G-Code Example

A Custom Macro B program that drills any number of holes on any PCD using variables and a WHILE loop.

By cnccode · Updated

A Custom Macro B program that drills any number of holes on any PCD using variables and a WHILE loop.

ItemValue
MachineCNC mill / machining centre (Fanuc-style)
UnitsMetric (G21)
Lines23

Program

G-code
O1014 (MACRO BOLT CIRCLE)
#1 = 8 (NUMBER OF HOLES)
#2 = 100. (PCD)
#3 = 0 (START ANGLE)
#4 = -12. (DEPTH)
G21 G17 G40 G49 G80 G90
T5 M06
G54 G00 X0 Y0
S1500 M03
G43 H05 Z25. M08
#10 = 0
WHILE [#10 LT #1] DO1
#11 = #3 + #10 * 360 / #1
#12 = #2 / 2 * COS[#11]
#13 = #2 / 2 * SIN[#11]
G98 G81 X#12 Y#13 Z#4 R2. F150.
#10 = #10 + 1
END1
G80
M09
G91 G28 Z0
G90
M30

▶ Simulate in the G-code viewer

How it works

  • Change #1–#4 to reuse the program for any pattern.
  • Requires Custom Macro B (standard on most modern Fanuc and Haas controls).
  • The G-code viewer does not expand macros; test with single block.

Codes used in this program

Always check feeds, speeds, offsets and clearances for your own machine and tooling, and prove new programs with single block and reduced rapid.

More milling programs