G-code
Custom G-code
Write your own G-code blocks for program start and end, tool change, spindle, coolant and vacuum, with variables, optional values and mode macros, checked as you type.
Machine › Machines… › choose a machine › Settings… › Custom G-code section › G-code Blocks: the blocks Dusty writes at specific moments of the program, grouped into Program and operations, Tool, Spindle, Coolant and vacuum:
- Header (program start) and Program end;
- Operation start and Operation end;
- Tool change (it must stop the program:
M0,M6…) and Tool length probe; - Spindle on (clockwise, counterclockwise), Spindle off;
- Mist (M7), Flood (M8), Coolant off, Vacuum on, Vacuum off;
- Dwell (spindle spin-up, drilling pauses).
Each block says what it does, when it is written and whether it is written for this machine. A block left at its default follows the flavor; Back to Default Block clears your text; an empty custom block writes nothing. The text is typed in a fixed-width editor; the Insert menu adds a variable or a macro. Problems are shown at each keystroke, with their line, and the preview shows the expanded block with example values. As long as a block written for the machine has an error, OK is refused: the G-code could not be produced.
Variables
{name} is replaced by its value.
| Variable | Value |
|---|---|
tool_number, tool_name, tool_diameter, tool_angle | Number, name, diameter and included angle of the tool (no angle for an end mill). |
rpm | Spindle speed written (none with the spindle off). |
feed | Last feed rate written. |
operation, section, program | Operation name, its rank (from 1), program name. |
safe_z, tool_change_z | Safe height, height of the retract before a tool change. |
x, y, z | Current position (none when unknown, for example after a tool change). |
units | mm or in. |
message | Tool change prompt (tool change block only). |
dwell | Dwell duration (dwell block only). |
Lengths and feeds are written in the unit of the line (the program’s, or the one a macro sets).
Optional values and conditional lines:
{?name}: the line disappears if the variable has no value. Without?, a variable without a value is an error: Dusty refuses to produce the G-code rather than write a wrong line.{*name}: the line is only written if the value has changed since it was last written.[S]{rpm}: the word (the letter and its value) is only written if the value has changed; a line made only of unchanged words disappears.- A line that can disappear must not carry the code that does the block’s job (
M0/M6of the tool change,M3/M4,M5): Dusty refuses it.
Mode macros
|REL| (relative distances, G91), |ABS| (absolute, G90), |MM| (G21), |INCH| (G20) change the mode for the block; |RESTORE| is required after them and restores the program’s modes. A block that leaves another mode active is followed by the codes that restore the program’s, with a warning.
Reserved characters
{ } [ ] | are used by templates; write \{, \}, \[, \], \| (and \\) to get them as is (or with the escape character chosen in the post-processor options). A control byte is written \x18 (from 00 to 7F); GRBL and Smoothieware controllers would read it as an immediate command: it is refused there, like ?, ! and ~.
Example of a tool change block for GRBL that raises the tool before the pause:
|MM|G0 Z{tool_change_z}|RESTORE|
T{tool_number}
M0 ({message})
This manual is also built into Dusty: press F1, or open the Help menu, to read the topic for what you are doing. A mistake, a missing answer? Tell us
Try it in Dusty, for free.
Free CNC milling software: design, toolpaths and machine control. Mac, iPad, iPhone, Windows and Linux.