Articles on: SimplyPrint features

G-code snippets, variables, and assigning macros

Snippets are the reusable building blocks behind G-code macros, and variables make them work across printers of different sizes and firmware. This guide covers how to create and manage snippets, the full variable reference, math and conditional logic, and how snippets get assigned to your macros and printers.


New to macros? Start with The G-code macros feature for the big picture, then come back here for the details.


Contents


Creating a snippet

  1. Open Settings, then the Gcode Macros tab.
  2. Click the + button in the top-right, or use Create snippet from the snippet picker inside any macro editor.
  3. Give the snippet a name (up to 32 characters) and an optional description.
  4. Write your G-code, one command per line, in the editor.
  5. Save.


The create-snippet dialog with a name, description, and the G-code editor


Once saved, the snippet is available to drop into any macro and to run on demand from the Printers panel.


Managing your snippet library

All your snippets appear in a searchable table at the bottom of the Gcode Macros tab. From there you can:


  • Search by name or description.
  • Edit a snippet (the change applies everywhere the snippet is used).
  • Delete one or several snippets at once.
  • Reorder snippets by dragging rows.


The snippet library table with search and row actions


Editing a snippet updates every macro that includes it. If several printers rely on the same snippet, double-check the result with the View button on the affected macros after editing.


Adding snippets to a macro

Inside any macro editor, open the Include snippets menu. You'll see your snippets grouped (organization, personal, official, and a built-in standard snippet where relevant), plus a search box and a Create snippet shortcut.


Click a snippet to insert it as a labelled block in the macro. You can:


  • Stack several snippets in a single macro.
  • Mix snippets with raw G-code lines.
  • Reuse the same snippet more than once in the same macro.
  • Reorder or remove blocks as you like.


This is what makes snippets powerful: write the G-code once, then assemble macros from those pieces instead of duplicating commands.


Variables

A variable is a placeholder you put in your G-code. When the macro runs, SimplyPrint replaces it with the correct value for the printer it's sent to. That's how one snippet can heat every printer to its own maximum or find the center of any bed.


Insert variables from the Variables menu in the editor toolbar (search, then click to insert), or just type { and pick from autocomplete.


These printer variables are always available:


Variable

What it is

{printer_model}

Printer model name

{printer_brand}

Printer brand name

{printer_id}

Printer ID

{bed_x}

Bed X length in mm

{bed_y}

Bed Y length in mm

{bed_width}

Alias for bed Y

{max_height}

Max print height in mm

{nozzle_diam}

Nozzle diameter in mm

{screws_offset}

Offset between the bed and the screws below it, in mm

{max_extruder_temp}

Max hot end temperature in degrees

{max_bed_temp}

Max bed temperature in degrees

{bowden_length}

Length of the bowden tube in mm

{filament_diameter}

Supported filament diameter in mm

{x_travel_speed}

X axis travel speed in mm/min

{y_travel_speed}

Y axis travel speed in mm/min

{z_travel_speed}

Z axis travel speed in mm/min

{counter}

Counter for loops, starts at 0


There are also firmware and connection flags you can test in conditions, such as {firmware_is_marlin}, {firmware_is_klipper}, {firmware_is_bambu}, {firmware_is_prusa}, {firmware_is_duet}, and the API checks {api_is_octoprint}, {api_is_moonraker}, {api_is_bambu}, and {api_is_ultimaker} (each also has a _is_not_ variant).


The variables menu, grouped and searchable, inside the macro editor


When you're working with a print-start or print-end macro, the SimplyPrint Slicer variables (such as {temp}, {bed_temp}, {layer}, and {progress}) become available too.


Math with variables

You can run a simple calculation inside the braces. For example, to find the center of any bed:


G0 X{{bed_x} / 2} Y{{bed_y} / 2}


Other examples: {{bed_x} - 25} or {{bed_x} / {bed_y}}.


One calculation per expression, and you can't nest calculations. So {{bed_x} / 2} works, but { { {bed_x} / {bed_y} } / 2 } does not.


Conditional logic and loops

You can send different G-code depending on the printer. Conditions use {#if ...} and support these operators:


Operator

Meaning

Example

==

Equals

{#if bed_x == 200}

!=

Not equals

{#if bed_x != 200}

>

Greater than

{#if bed_x > 200}

<

Less than

{#if bed_x < 200}

<=

Less than or equal

{#if bed_x <= 200}

~

Contains

{#if "some text" ~ "text"}

=~

Regex match

{#if "some text" =~ /text/}


You can also loop with {#while ...} using the {counter} variable, for example {#while counter < 10}. This lets one snippet do something like home and probe a configurable number of times, or branch G-code by firmware without maintaining separate snippets per printer.


Macro-specific and print-context variables

Some macros expose extra variables that only make sense in that context:


  • Macro-specific variables appear for control macros. For example, the "Change print speed" macro provides {var_speed}, "Move axis" provides {var_direction}, {var_step} and {var_speed}, and the Z-offset calibration macros provide {var_step} and {var_calculated_offset}. If a macro expects an important variable and your G-code doesn't use it, the editor flags it so you don't miss it.
  • Print-context variables (such as {print_file_name}, {print_current_layer}, {print_current_progress}, and {filament_usage_gram}) are available in the AutoPrint clear-bed and on-end macros, where there's an active or just-finished print to read from.


Organization, personal, and inherited snippets

In a multi-user account, snippets and macros come in two flavours:


  • Organization snippets and macros are shared by everyone in the account.
  • Personal snippets and macros only affect your own prints, if your account allows personal macros.


Personal macros automatically inherit the organization's snippets, so a personal macro can reuse the shared building blocks instead of duplicating them. New accounts also start with a built-in Standard snippet wired into the relevant macros, which you can keep as-is or replace.


For how macros are assigned per printer, the override warnings, and the different macro types, see the overview.



Updated on: 25/06/2026

Was this article helpful?

Share your feedback

Cancel

Thank you!