Bird
0
0
CNC Programmingscripting~5 mins

G-code program structure in CNC Programming

Choose your learning style9 modes available
Introduction
G-code program structure shows how to organize instructions so a CNC machine can follow them step-by-step to make parts.
When you want to tell a CNC machine how to cut or shape a part.
When you need to start a new CNC machining job with clear steps.
When you want to make sure the machine runs safely and correctly.
When you want to repeat the same machining process multiple times.
When you want to add comments or notes inside your CNC program.
Syntax
CNC Programming
O1234 (Program number and start)
N10 G21 (Set units to millimeters)
N20 G90 (Set absolute positioning)
N30 G01 X10 Y10 F100 (Move in a straight line)
N40 M30 (End program)
O number is the program ID and usually appears at the start.
N numbers are line numbers to organize commands clearly.
Examples
A simple program that sets absolute mode, moves quickly to X0 Y0, then ends.
CNC Programming
O1000
N10 G90
N20 G00 X0 Y0
N30 M30
Program using millimeters, moves in a straight line at feed rate 200, then ends.
CNC Programming
O2000
N10 G21
N20 G01 X50 Y50 F200
N30 M30
Program with comments explaining each step.
CNC Programming
O3000
N10 (Start of program)
N20 G90 (Absolute positioning)
N30 G00 X0 Y0 (Rapid move to origin)
N40 M30 (Program end)
Sample Program
This program draws a square by moving the tool around the edges using straight line moves.
CNC Programming
O1234 (Sample G-code program)
N10 G21 (Set units to millimeters)
N20 G90 (Use absolute positioning)
N30 G00 X0 Y0 (Rapid move to start point)
N40 G01 X50 Y0 F150 (Cut straight line at feed 150)
N50 G01 X50 Y50 (Cut straight line up)
N60 G01 X0 Y50 (Cut straight line left)
N70 G01 X0 Y0 (Cut straight line down to start)
N80 M30 (End of program)
OutputSuccess
Important Notes
Always start with a program number (O code) to identify your program.
Use line numbers (N codes) to keep commands organized and easy to follow.
Include comments in parentheses to explain what each part does for easier reading.
Summary
G-code programs start with a program number and end with M30 to stop.
Line numbers help organize commands and make the program easier to read.
Commands include setting units, positioning mode, moving the tool, and ending the program.