Fanuc Bolt Hole Circle Macro Generator
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.
Fill in
Bolt hole circle program
O1201 (BOLT HOLE CIRCLE, 6 HOLES ON R40.0) G90 G54 G17 G40 G49 G80 T5 M6 S2400 M3 G0 X0.0 Y0.0 G43 H5 Z50.0 M8 (HOLE PATTERN DATA) #1=0 (HOLE COUNTER) #2=6 (NUMBER OF HOLES) #3=0.0 (START ANGLE) #4=360/#2 (ANGLE STEP) G52 X0.0 Y0.0 (SHIFT LOCAL ORIGIN TO CIRCLE CENTER) G90 G16 (POLAR COORDINATE MODE) WHILE [#1 LT #2] DO1 G81 X40.0 Y[#3+#1*#4] Z-18.0 R2.0 F220.0 #1=#1+1 END1 G80 G15 (CANCEL CYCLE AND POLAR MODE) G52 X0 Y0 (CANCEL LOCAL SHIFT) G0 Z50.0 M9 M5 G91 G28 Z0 G28 Y0 M30 %
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.
NC program control in your ERP
Optional: a conversation on controlling NC program revisions against part and routing data.
Optional. The tool and every export work without this. No spam.
How to use the generator
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.
- 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
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
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
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.
Frequently Asked Questions
What is G16 used for?
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?
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?
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?
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.
If you want NC programs generated and reviewed against ERP routings and approved tools, we can discuss how that could work with human approval.
Related Tools
Fanuc Macro B System Variables Reference
A lookup table of widely used Fanuc Custom Macro B variable numbers for offsets, positions, timers and alarms.
Developer ToolsCNC Program Header and Safe Start Block Generator
Create a consistent program header with revision comments, a safe start line and a tool change sequence for a mill.
MES & Shop FloorCNC Drilling Cycle Time Calculator
Calculate spindle speed, feed rate and total time for a drilling job with peck cycles, and see how peck depth affects time.
MES & Shop FloorCNC Pre-Run Setup Verification Checklist
A checklist for the operator or setup technician to confirm program, tools, offsets, workholding and safety before running production.
More Developer Tools tools
See all- SAP Sales Order ABAP SELECT Generator (VBAK, VBAP, VBFA)
- SAP Sales Order Create BAPI ABAP Generator (BAPI_SALESORDER_CREATEFROMDAT2)
- SAP ABAP Open Items SELECT Generator
- SAP ACDOCA SQL Query Generator
- SAP QM Inspection Lot ABAP SELECT Generator
- SAP Quality Notification Pareto SQL Query Generator
- SAP QM Usage Decision BAPI Skeleton
- ABAP Custom Exception Class Generator
- ABAP Unit Test Class Generator