0
0
Ev-technologyHow-ToBeginner · 4 min read

G Code for Milling a Rectangle: Syntax and Example

To mill a rectangle using G-code, use G0 to move to the start point, then G1 to cut along each side by specifying X and Y coordinates sequentially. Repeat the moves to complete the rectangle shape with precise linear cuts.
📐

Syntax

The basic G-code commands to mill a rectangle are:

  • G0 X... Y...: Rapid move to the starting corner without cutting.
  • G1 X... Y... F...: Linear cutting move to the next corner at feed rate F.
  • Repeat G1 moves for each side of the rectangle.
  • M30: Program end.

Coordinates X and Y define the corners of the rectangle.

gcode
G0 X0 Y0
G1 X50 Y0 F100
G1 X50 Y30
G1 X0 Y30
G1 X0 Y0
M30
💻

Example

This example mills a 50mm by 30mm rectangle starting at the origin (0,0). It moves quickly to the start, then cuts each side at a feed rate of 100 mm/min.

gcode
G21 ; Set units to millimeters
G90 ; Use absolute positioning
G0 X0 Y0 ; Rapid move to start
G1 Z-5 F50 ; Lower tool to cutting depth
G1 X50 Y0 F100 ; Cut first side
G1 X50 Y30 ; Cut second side
G1 X0 Y30 ; Cut third side
G1 X0 Y0 ; Cut fourth side
G0 Z5 ; Raise tool
M30 ; End program
⚠️

Common Pitfalls

Common mistakes when milling a rectangle include:

  • Not setting the correct units with G21 (millimeters) or G20 (inches).
  • Forgetting to lower the tool before cutting, causing no material removal.
  • Using relative positioning (G91) unintentionally, which can cause wrong coordinates.
  • Not specifying feed rate F during cutting moves, leading to default or unsafe speeds.

Always verify coordinate values and tool height before running the program.

gcode
Wrong approach:
G0 X0 Y0
G1 X50 Y0
G1 X50 Y30
G1 X0 Y30
G1 X0 Y0
M30

Right approach:
G21
G90
G0 X0 Y0
G1 Z-5 F50
G1 X50 Y0 F100
G1 X50 Y30
G1 X0 Y30
G1 X0 Y0
G0 Z5
M30
📊

Quick Reference

CommandDescription
G0 X... Y...Rapid move to position without cutting
G1 X... Y... F...Linear cut move at feed rate F
G21Set units to millimeters
G90Set absolute positioning mode
M30End of program

Key Takeaways

Use G0 to move quickly to the rectangle start point without cutting.
Use G1 with X and Y coordinates to cut each side of the rectangle at a set feed rate.
Always set units with G21 and positioning mode with G90 before cutting.
Lower the tool to the cutting depth before starting the cut and raise it after.
Check coordinates and feed rates carefully to avoid mistakes.