Master CNC
Blog · 6 min read · 26 Oct 2026

Macro B example: bolt hole circle

A bolt hole circle is the classic job for a macro: the same few lines of maths, with different numbers every time. Write it once, and every new flange is one line in the main program.

The maths

For a circle with centre (cx, cy) and diameter D, hole number n of H holes, starting at angle A:

angle = A + n × 360 ÷ H
X = cx + D/2 × cos(angle)
Y = cy + D/2 × sin(angle)

Angles are measured counter-clockwise from the +X direction, in degrees.

G65 P9100 bolt hole circle call; X and Y from centre plus radius times cosine and sine
Centre, diameter, start angle, number of holes.

The macro

O9100 (BOLT HOLE CIRCLE)
(X=#24 Y=#25 D=#7 A=#1 H=#11)
(Z=#26 R=#18 F=#9)
#10 = 0
WHILE [#10 LT #11] DO1
  #12 = #1 + #10 * 360. / #11
  #13 = #24 + #7 / 2. * COS[#12]
  #14 = #25 + #7 / 2. * SIN[#12]
  G99 G81 X#13 Y#14 Z#26 R#18 F#9
  #10 = #10 + 1
END1
G80
M99

The letters in the G65 call land in fixed variables: X → #24, Y → #25, D → #7, A → #1, H → #11, Z → #26, R → #18, F → #9. See Macro B basics.

Calling it

T3 M06  (D8.5 DRILL)
G90 G54 G00 X50. Y40. S1500 M03
G43 H03 Z20. M08
G65 P9100 X50. Y40. D80. A15. H6. Z-12. R2. F120.
G00 Z100. M09

Six holes on a Ø80 circle centred at X50 Y40, the first at 15°.

Hand-check the first holes

HoleAngleXY
115°88.63750.353
275°60.35378.637
3135°21.71668.284

For hole 1: 50 + 40 × cos 15° = 50 + 38.637 = 88.637, and 40 + 40 × sin 15° = 40 + 10.353 = 50.353. Run the macro in graphics and compare the first hole with your hand calculation before cutting.

Making it better

  • Pass the cycle as an argument, so the same macro can spot, drill and tap.
  • Check the arguments at the start: IF [#11 EQ #0] GOTO 900 catches a missing H (#0 is always empty), with N900 #3000 = 1 (H MISSING).
  • Many controls also have a built-in bolt hole cycle (for example G70.1 or a conversational pattern); check if yours does.

Common mistakes

  1. No decimal points in the arguments: D80 may be read as 0.080.
  2. Integer division: write 360. with a decimal point.
  3. Start angle measured clockwise on the drawing; the macro measures counter-clockwise.

Use a free program number range your machine builder does not use (O9000 – O9999 programs are often protected by a parameter). Test in graphics and single block first.

Try it in Master CNC

Calculators, process sheet to program, simulation, codes and lessons. Free to start, no sign-in, on phone and laptop.

Open the app