G-code is the common name for the most widely used computer numerical control (CNC) programming language, which has many implementations. Used mainly in automation, it is part of computer-aided engineering. G-code is sometimes called G programming language.
In fundamental terms, G-code is a language in which people tell computerized machine tools what to make and how to make it. The “what” and “how” are mostly defined by instructions on where to move to, how fast to move, and through what path to move. The most common situation is that a cutting tool is moved according to these instructions, cutting away excess material to leave only the finished workpiece. Non-cutting tools, such as cold-forming tools, burnishing tools, or measuring probes, are also sometimes involved.
For example look the following code which uses 3 different tools (T01,T02,T06) and ramping technique to cut an ashtray . The tool draws 4 circles outside the piece of metal , an inside big one , 4 paths (for the cigarette :P) and some holes , at XYZ -axis (it looks much more fun typing at a cnc-simulator and solidworks .
G54 G40 G90 G21
M06 T02
G00 Z05 M09
G00 X75 Y75
G01 Z0 M03 G94 F240 G97 S417 M08
G01 X110 Y75 Z-5
G17 G03 I-35 J0
G00 X75 Y75
G01 Z0 M03 G94 F240 G97 S417 M08
G01 X110 Y75 Z-10
G17 G03 I-35 J0 F240
G00 X75 Y75
G01 Z-5 M09
G01 Z-5 M03 G94 100 G97 S417 M08
G01 X100 Y75 Z-5
G17 G03 I-25 J0 F240
G01 Z0 M03 G94 F240 G97 S417 M08
G01 X100 Y75 Z-10
G17 G03 I-25 J0 F240
G01 Z-5 M09
G01 Z-5 M03 G94 F240 G97 S417 M08
G01 X90 Y75 Z-5
G17 G03 I-15 J0 F240
G00 X75 Y75
G01 Z0 M03 G94 F240 G97 S417 M08
G01 X90 Y75 Z-10
G17 G03 I-15 J0 F240
G00 Z+5
M06 T02
G00 X75 Y166 M09
G00 X-3.98 Y163.42
G01 Z0 M03 G94 F240 G97 S417 M08
G17 G03 X160.67 Y167.43 R160
G00 X173.55 Y169.63
G17 G03 X 169.35 Y-13.62 R160
G00 X161.54 Y-17.98
G17 G03 X-8.78 Y -16.25 R160
G00 X-20.17 Y-14.85
G17 G03 X-20.47 Y165.29 R160
G00 X-3.98 Y163.42
G00 Z-10
G03 X160.7 Y167.43 R160
G00 X173.55 Y169.63
G17 G03 X 169.35 Y-13.62 R160
G00 X161.54 Y-17.98
G17 G03 X-8.78 Y -16.25 R160
G00 X-20.17 Y-14.85
G17 G03 X-20.47 Y165.29 R160
G00 X-3.98 Y163.42
G00 Z-15.2
G03 X160.7 Y167.43 R160
G00 X173.55 Y169.63
G17 G03 X169.35 Y-13.62 R160
G00 X161.54 Y-17.98
G17 G03 X-8.78 Y -16.25 R160
G00 X-20.17 Y-14.85
G17 G03 X-20.47 Y165.29 R160
G00 Z+5
M06 T06
G00 X14.9 Y135.10 Z0
G83 Z-5 R6 F240 Q5
G00 Z+5
G00 Z0
G83 Z-10 R6 F240 Q5
G00 Z+5
G00 Z0
G83 Z-15.2 R6 F240 Q5
G00 Z+5
G00 X135.10 Y 135.10 Z0
G83 Z-5 R6 F240 Q5
G00 Z+5
G00 Z0
G83 Z-10 R6 F240 Q5
G00 Z+5
G00 Z0
G83 Z-15.2 R6 F240 Q5
G00 Z+5
G00 X135.10 Y 14.90 Z0
G83 Z-5 R6 F240 Q5
G00 Z+5
G00 Z0
G83 Z-10 R6 F240 Q5
G00 Z+5
G00 Z0
G83 Z-15.2 R6 F240 Q5
G00 Z+5
G00 X14.90 Y 14.90 Z0
G83 Z-5 R6 F240 Q5
G00 Z+5
G00 Z0
G83 Z-10 R6 F240 Q5
G00 Z+5
G00 Z0
G83 Z-15.2 R6 F240 Q5
G00 Z+5
G00 X75 Y150
M06 T01
G01 Z-5 M03 G94 F100 G97 S417 M08
G01 X75 Y0 Z-5
G00 Z+5
G00 X0 Y 75
G01 Z-5 M03 G94 F100G97 S417 M08
G01 X150 Y75