Automating Z Offset Adjustments
Introduction
Section titled “Introduction”Different filament materials often need different Z offsets for good bed adhesion and first layer squish. Adjusting the offset by hand for every print is slow and error prone. This guide shows how to configure your slicer to apply the Z offset automatically for each print. It also shows how to change the PRINT_END macro so the Z offset returns to its default when a print finishes.
Prerequisites
Section titled “Prerequisites”You need:
- A 3D printer running Klipper
- A slicer that supports filament-specific start G-code, such as:
- PrusaSlicer
- SuperSlicer
- OrcaSlicer
- “Advanced” settings enabled in your slicer, to reach the configuration options used below.
Modifying the PRINT_END macro
Section titled “Modifying the PRINT_END macro”Your printer.cfg should already contain a PRINT_END macro, since it is part of the standard Voron configuration. If it does not, use the template in the callout below. Append the following command to the end of the macro:
SET_GCODE_OFFSET Z=0If your macro uses SAVE_GCODE_STATE and RESTORE_GCODE_STATE, put the new command after RESTORE_GCODE_STATE. RESTORE_GCODE_STATE also restores the saved G-code offset, so a command placed before it is undone. The offset would then change a little with each print instead of returning to the baseline.
SET_GCODE_OFFSET Z=0 sets the Z offset to zero, so later G-code commands run without a Z offset. The next print starts from a known baseline.
Configuring filament settings in your slicer
Section titled “Configuring filament settings in your slicer”This section uses PrusaSlicer as an example. Other slicers work the same way.
Step 1: Open custom G-code
Section titled “Step 1: Open custom G-code”In your slicer, open Filament Settings and select the Custom G-code entry (highlighted in blue in the screenshot below).
Step 2: Add start G-code
Section titled “Step 2: Add start G-code”SET_GCODE_OFFSET Z_ADJUST=0.3
This uses SET_GCODE_OFFSET again, but with the Z_ADJUST parameter instead of the Z parameter used in PRINT_END. Z sets the offset to the given value. Z_ADJUST adds the given value to the current offset. For example, SET_GCODE_OFFSET Z=-0.2 followed by SET_GCODE_OFFSET Z_ADJUST=0.3 gives a Z offset of 0.1. This is why the offset must be reset after each print.
Verification
Section titled “Verification”To check that the adjustment is applied:
-
Slice and start a new print.
-
Watch the Z offset while the printer prepares the print. If the configuration is correct, the web UI shows the expected Z offset in the Toolhead card, as in the screenshot below:

Further reading
Section titled “Further reading”- Klipper SET_GCODE_OFFSET documentation