Introduction
G-code is the language of numerically controlled machines, standardised as RS-274 and used by CNC mills and lathes for decades. 3D printers use their own dialects of it. A slicer turns a model into a G-code file made for one printer: every move of the print head, every change of temperature and every length of filament to push.
Because the file is made for a particular printer, nozzle and material, it is the last step before printing and is rarely shared between different machines. Prusa printers also accept a compact binary G-code.
Structure
A G-code file is plain text, one command per line. Each line starts with a command letter and number, followed by parameters, each a letter and a value. A semicolon starts a comment, which slicers use for settings, layer markers and print time estimates.
| Command | Meaning |
|---|---|
G0, G1 | Move to the given X, Y, Z, pushing E of filament, at feed rate F |
G28 | Move to the home position |
G90, G91 | Absolute or relative positions |
M82, M83 | Absolute or relative extrusion |
M104, M109 | Set the nozzle temperature, without or with waiting |
M140, M190 | Set the bed temperature, without or with waiting |
; layer 1
M140 S60 ; bed to 60 °C
M109 S210 ; nozzle to 210 °C and wait
G28 ; home all axes
G90 ; absolute positions
M82 ; absolute extrusion
G1 Z0.2 F3000
G1 X50 Y50 E2.5 F1500
Files use the extensions .gcode, .gco or
.g. There is no signature or header; the first comment usually names
the slicer that wrote the file.
In this reference
- Line syntax – fields and parameter letters, numbers, comments, line numbers and checksums with a worked example, quoted strings, expressions and modal state
- Commands – every G, M, T and D code in the RepRap register, with the firmwares that give one number different meanings
- Slicer comments – producer lines, PrusaSlicer and Cura headers, layer and feature markers, statistics, settings blocks and embedded thumbnails
Not described
Known, not yet covered
- Reference: the per-firmware parameters of every command (the RepRap wiki gives them), Klipper’s word-form extended commands such as SET_PRESSURE_ADVANCE and EXCLUDE_OBJECT (commands page), and the comment conventions of other slicers: Simplify3D, ideaMaker, KISSlicer and the additions of Bambu Studio and OrcaSlicer (comments page).
- Viewer: none yet; the site shows the hex viewer only.
Links
Software
- PrusaSlicer – Prusa Research’s free open source slicer (Windows, macOS, Linux)
- UltiMaker Cura – free open source slicer from UltiMaker (Windows, macOS, Linux)
- Bambu Studio – Bambu Lab’s free slicer for its printers (Windows, macOS, Linux)
- OrcaSlicer – free open source slicer for many printer brands (Windows, macOS, Linux)
- OctoPrint – web interface that sends G-code to a printer (runs on Linux and others)
- Klipper – printer firmware that runs G-code with the help of a host computer
- Marlin – the most widely used firmware for hobby 3D printers
Reference
- G-code index – the Marlin firmware’s documentation of each command
- G-code – the RepRap wiki’s list, with the commands of each printer firmware