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.
Contents
- Creating a snippet
- Managing your snippet library
- Adding snippets to a macro
- Variables
- Math with variables
- Conditional logic and loops
- Macro-specific and print-context variables
- Organization, personal, and inherited snippets
Creating a snippet
- Open Settings, then the Gcode Macros tab.
- Click the + button in the top-right, or use Create snippet from the snippet picker inside any macro editor.
- Give the snippet a name (up to 32 characters) and an optional description.
- Write your G-code, one command per line, in the editor.
- Save.

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.

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 name |
| Printer brand name |
| Printer ID |
| Bed X length in mm |
| Bed Y length in mm |
| Alias for bed Y |
| Max print height in mm |
| Nozzle diameter in mm |
| Offset between the bed and the screws below it, in mm |
| Max hot end temperature in degrees |
| Max bed temperature in degrees |
| Length of the bowden tube in mm |
| Supported filament diameter in mm |
| X axis travel speed in mm/min |
| Y axis travel speed in mm/min |
| Z axis travel speed in mm/min |
| 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).

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}}.
{{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 | |
| Not equals | |
| Greater than | |
| Less than | |
| Less than or equal | |
| Contains | |
| Regex match | |
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.
Related articles
- The G-code macros feature - macros, the editor, macro types, and per-printer assignment
- SimplyPrint Slicer variables - placeholders available when slicing
- What is G-code for 3D printing, and how to read and write it
- Z-Offset calibration: fine-tune your first layer remotely
Updated on: 25/06/2026
Thank you!