0
0
Ev-technologyHow-ToBeginner · 3 min read

G Code for Drilling Hole Pattern: Syntax and Example

To create a drilling hole pattern in G-code, use G81 drilling cycle with coordinates for each hole. Move the tool to each hole position using G00 rapid moves, then call G81 with depth and retract parameters to drill holes in sequence.
📐

Syntax

The basic syntax for drilling a hole pattern uses the G81 drilling cycle combined with rapid moves (G00) to position the tool at each hole location.

  • G00 X... Y...: Rapid move to hole position.
  • G81 Z... R... F...: Drilling cycle where Z is drilling depth, R is retract height, and F is feed rate.
  • G80: Cancels drilling cycle after all holes are drilled.
gcode
G00 Xx Yy ; Move to hole position
G81 Z-Depth RRetract FFeedrate ; Drill hole
G80 ; Cancel drilling cycle
💻

Example

This example drills a pattern of three holes at different X and Y coordinates using the G81 drilling cycle. It moves rapidly to each hole, drills to a depth of -5 mm, retracts to 2 mm above the surface, and uses a feed rate of 100 mm/min.

gcode
G21 ; Set units to millimeters
G90 ; Absolute positioning
G00 Z5 ; Raise tool to safe height

G00 X10 Y10 ; Move to first hole
G81 Z-5 R2 F100 ; Drill hole

G00 X20 Y10 ; Move to second hole
G81 Z-5 R2 F100 ; Drill hole

G00 X30 Y10 ; Move to third hole
G81 Z-5 R2 F100 ; Drill hole

G80 ; Cancel drilling cycle
G00 Z5 ; Raise tool
M30 ; End of program
Output
Tool moves to X10 Y10, drills to -5 mm depth, retracts to 2 mm Tool moves to X20 Y10, drills to -5 mm depth, retracts to 2 mm Tool moves to X30 Y10, drills to -5 mm depth, retracts to 2 mm Cycle ends and tool raises
⚠️

Common Pitfalls

Common mistakes when programming hole patterns include:

  • Forgetting to cancel the drilling cycle with G80, causing unintended drilling at later moves.
  • Not setting the retract height R properly, which can cause the tool to drag on the surface.
  • Using incorrect coordinates or forgetting to move the tool before drilling.
  • Not setting units (G20 for inches or G21 for millimeters) and positioning mode (G90 absolute or G91 incremental).
gcode
;; Wrong: Missing G80 cancels drilling cycle
G00 X10 Y10
G81 Z-5 R2 F100
G00 X20 Y10
G00 X30 Y10 ; This will drill unintentionally here

;; Correct: Cancel drilling cycle
G00 X10 Y10
G81 Z-5 R2 F100
G00 X20 Y10
G81 Z-5 R2 F100
G00 X30 Y10
G81 Z-5 R2 F100
G80
📊

Quick Reference

G-code CommandDescription
G00Rapid move to position without cutting
G81Drilling cycle with parameters for depth, retract, and feed
G80Cancel drilling cycle
G90Absolute positioning mode
G21Set units to millimeters
G20Set units to inches

Key Takeaways

Use G81 drilling cycle combined with G00 moves to drill hole patterns efficiently.
Always cancel drilling cycles with G80 to avoid unintended drilling.
Set correct units and positioning modes before programming hole patterns.
Specify retract height (R) to protect the tool and workpiece surface.
Verify all hole coordinates before running the program to prevent errors.