# Fanuc Bolt Hole Circle Macro Generator

> Source: https://netray.co/tools/fanuc-bolt-hole-circle-macro-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Fill in center, radius, number of holes and drill cycle values and get a ready to review Fanuc macro for a bolt hole pattern.

## Category

developer

## Industry

Machining

## Audience

- CNC programmer
- Machinist

## Tool

**Kind:** template

**Output:** code

**Language:** text

**Fields:**

#### Program number

**Key:** prog

**Type:** text

**Default:** 1201

#### Circle center X

**Key:** cx

**Type:** text

**Default:** 0.0

#### Circle center Y

**Key:** cy

**Type:** text

**Default:** 0.0

#### Bolt circle radius

**Key:** radius

**Type:** text

**Default:** 40.0

#### Number of holes

**Key:** count

**Type:** text

**Default:** 6

#### Start angle (degrees)

**Key:** start

**Type:** text

**Default:** 0.0

#### Drill tool number

**Key:** tool

**Type:** text

**Default:** 5

#### Spindle speed (RPM)

**Key:** rpm

**Type:** text

**Default:** 2400

#### Drill depth Z

**Key:** zdepth

**Type:** text

**Default:** -18.0

#### R plane

**Key:** rplane

**Type:** text

**Default:** 2.0

#### Feed (per minute)

**Key:** feed

**Type:** text

**Default:** 220.0

#### Safe Z clearance

**Key:** safez

**Type:** text

**Default:** 50.0

**Blocks:**

#### Bolt hole circle program

**Body:** O{{prog}} (BOLT HOLE CIRCLE, {{count}} HOLES ON R{{radius}})
G90 G54 G17 G40 G49 G80
T{{tool}} M6
S{{rpm}} M3
G0 X{{cx}} Y{{cy}}
G43 H{{tool}} Z{{safez}}
M8
(HOLE PATTERN DATA)
#1=0 (HOLE COUNTER)
#2={{count}} (NUMBER OF HOLES)
#3={{start}} (START ANGLE)
#4=360/#2 (ANGLE STEP)
G52 X{{cx}} Y{{cy}} (SHIFT LOCAL ORIGIN TO CIRCLE CENTER)
G90 G16 (POLAR COORDINATE MODE)
WHILE [#1 LT #2] DO1
G81 X{{radius}} Y[#3+#1*#4] Z{{zdepth}} R{{rplane}} F{{feed}}
#1=#1+1
END1
G80 G15 (CANCEL CYCLE AND POLAR MODE)
G52 X0 Y0 (CANCEL LOCAL SHIFT)
G0 Z{{safez}}
M9
M5
G91 G28 Z0
G28 Y0
M30
%

**Notes:** Review before running. G52 and G16 behavior, the polar origin, and WHILE support (Macro B option) depend on your control and parameters. Prove out in single block with the machine locked or with the Z axis raised. For a peck cycle, replace G81 with G83 and add a Q value. Dwell, spot drilling and chamfer operations are not included.

## Content

**Intro:** A bolt hole circle is one of the most common patterns a CNC programmer writes, and calculating each X and Y by hand is slow and error prone. This generator builds a Fanuc Macro B program that uses polar coordinates and a WHILE loop so only a few values need to change.

**Sections:**

#### How to use the generator

**Body:** Enter the circle center, radius, number of holes, start angle and drilling data. The program appears on the right, ready to copy or export. Check the tool number, work offset and safe Z for your machine, then prove it out with a dry run before drilling any parts.

**Bullets:**

- Center is in the active work coordinate system
- Start angle is measured from the positive X axis
- Angle step is 360 divided by the number of holes
- Replace G81 with G83 for deep holes

#### How the program works

**Body:** G52 temporarily moves the local origin to the circle center so polar mode can work about that point. G16 then reads X as the radius and Y as the angle in degrees, so every hole becomes a radius and an angle. The WHILE loop adds one angle step each pass and calls the drilling cycle, which stays modal.

#### Checking the result

**Body:** For six holes at a 40 mm radius starting at zero degrees, holes fall every 60 degrees, with the first at X40 Y0 and the second at X20 Y34.641 relative to center. Confirm a couple of positions by hand, then verify with a graphic simulation or a first piece inspection against the drawing.

#### Common mistakes

**Body:** Forgetting to cancel G16 and G52 at the end of the pattern is the most dangerous error, since the following moves would still be interpreted in polar mode. Others include incorrect angle direction on mirrored setups, using the wrong plane (G17 is required), and starting the loop from a position inside the part.

**Cta:** If you want NC programs generated and reviewed against ERP routings and approved tools, we can discuss how that could work with human approval.

**Faq:**

#### What is G16 used for?

**Answer:** G16 turns on polar coordinate command mode on Fanuc controls. In G90 the first axis word is the radius and the second is the angle from the positive axis of the selected plane. G15 cancels it.

#### Does this work on a Haas control?

**Answer:** Haas supports G65 macros, WHILE loops and a G-code for bolt hole circles (G70, G71, G72), but G16 polar behavior and G52 differ. Use this output as a pattern and adapt it, or use the built-in bolt hole cycles.

#### How do I rotate the pattern?

**Answer:** Change the start angle. For six holes a start angle of 30 degrees puts holes at 30, 90, 150 and so on. Use a negative angle step in the code if the drawing requires counter-clockwise numbering.

#### Can I use it with a peck drilling cycle?

**Answer:** Yes. Replace G81 with G83 and add a Q value, for example Q3.0, to the same block. Check the peck and retract parameters on your control, since some use parameter 5114 for the retract amount.

## Search terms

bolt hole circle g code, fanuc bolt hole circle macro, g16 polar coordinates drilling, bolt circle cnc program generator, fanuc while loop drilling, g81 bolt hole pattern, bolt hole circle macro, cnc bolt pattern code

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
