cancel_print
Cancel the currently running print job while optionally preserving hotend, bed, and chamber temperatures to avoid cooling before a resume or swap.
Instructions
Cancel the currently running print job.
Sends cancel via MQTT (Bambu) or REST API (OctoPrint/Moonraker)
automatically.
The printer must have an active job (printing or paused).
:param preserve_temperatures: When ``True``, re-asserts the pre-cancel
hotend + bed (+ chamber, if expected_chamber_target is provided)
targets immediately after the cancel command, so the printer
does NOT cool down. Use this when you plan to swap in a
different file (e.g., a mid-print decoration resume 3MF) and need
bed adhesion + nozzle temperature held across the cancel-then-
start-print transition. Without this, Bambu firmware defaults
to cooling on cancel, which can warp the existing part or kill
bed adhesion on a partial print you're about to resume.
Default ``False`` preserves legacy behaviour (cool down to idle).
:param expected_tool_target: Optional caller-supplied tool target to
preserve. When provided AND ``preserve_temperatures=True``,
this overrides the introspected ``state.tool_temp_target``.
Useful when the printer was paused and the firmware has already
cleared the target (so a fresh state read returns 0) but the
caller knows what the pre-pause target was.
:param expected_bed_target: Same as above, for the bed. This is
the primary fix for Bambu A1 long-pause-then-cancel: the bed
target sometimes reads back as 0 from MQTT cache after a long
pause, and without an explicit override the cancel preservation
skips the bed restore.
:param expected_chamber_target: Optional chamber target (M141) to
re-assert via raw G-code. Not all printers expose chamber
heating via the adapter API, so this is sent as a raw M141
command best-effort. Pass ``None`` to skip chamber preservation.
WARNING: Cancellation is irreversible -- the print cannot be resumed
from where it left off UNLESS a resume-mode 3MF has been pre-staged
(see ``decorate_during_print`` and ``revert_mid_print``).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expected_bed_target | No | ||
| expected_tool_target | No | ||
| preserve_temperatures | No | ||
| expected_chamber_target | No |