Skip to content

Conditional Gcode Syntax Spec

Joseph Lenox edited this page May 31, 2017 · 22 revisions

- DRAFT -

Contents on this page are proposed and may not be implemented.

Conditional expressions

Conditional expressions has the following syntax:

  • {if expression}
  • {if not expression}

expression may take one of the following forms:

  • VARIABLE OPERATOR CONSTANT
  • VARIABLE OPERATOR CONSTANT
  • (subexpression) OPERATOR (subexpression)
  • OPERATOR subexpression

subexpression has the same forms as expression.

Available operators:

  • & or and - logical AND
  • | or or - logical OR
  • ! or not - logical NOT (inversion)
  • == or equals - equality comparison.

To apply a single condition to multiple lines, repeat it once for each line.

{if layer_num == 10}M104 S210
{if layer_num == 10}M600
  • If a conditional expression evaluates to false, all the characters until the end of the line are removed.
  • If a conditional expression fails to parse, it's silently left untouched.
  • Expressions may be chained for an implicit AND.
{if layer_num == 10}{if temperature_1 != 210}M104 S210

Value expressions

Any expression enclosed in two curly brackets, but not starting with {if is evaluated as an arithmetic expression: {foo - bar}. If evaluation fails, the expression is silently left untouched. If any float variables are used, return value will have decimals. If string variables are mixed with numeric variables, they are parsed as floats if they have a dot, or integers otherwise.

Value expressions can be used in conditional expressions by nesting them: {if {foo - bar} > 10}.