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.
A Custom Macro B program that drills any number of holes on any PCD using variables and a WHILE loop.
| Item | Value |
|---|---|
| Machine | CNC mill / machining centre (Fanuc-style) |
| Units | Metric (G21) |
| Lines | 23 |
Program
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
- Face Milling Program (Zig-Zag Passes)
- Outside Contour with Cutter Compensation (G41)
- Circular Pocket with Helical Entry
- Bolt Hole Circle with Polar Coordinates (G16)
- Peck Drilling a Hole Grid (G83)
- Rigid Tapping Program (M8 × 1.25)
- Internal Thread Milling M12 × 1.75
- Rectangular Pocket in Depth Passes Using a Subprogram
- Machining Multiple Parts with G54–G57
- Counterbore Holes for M6 Socket Head Screws
- Fine Boring a Precision Bore (G76 on a Mill)
- Milling a Slot with Ramping Entry
- Chamfering an Outside Edge with a Chamfer Mill
- Spindle Warm-Up Program
- Setting a Work Offset Automatically with a Probe (G31)
- GRBL Router: Rectangle Cut-Out in Depth Passes
- GRBL / LinuxCNC Touch Plate Z Probe (G38.2)
- Haas G12 / G13 Circular Pocket in One Line
- Haas M97 Local Subprogram for Repeated Features
- High-Speed Peck Drilling in Aluminum (G73)
- Helical Boring a Ø20 Hole with a 10 mm End Mill