cancel_print
Cancel the active 3D print job and optionally keep the nozzle and bed hot for a quick file swap or mid-print update, preventing warping and adhesion loss.
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 printer_name: Which printer to stop. Omit to stop the default
printer, which is what this did before it could be aimed. Owning
more than one printer is free at every tier (only running them at
the same time is a fleet feature), so the second machine is a
supported setup on a free licence — and control of a hot machine
is never something a licence takes away.
: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 |
|---|---|---|---|
| printer_name | No | ||
| expected_bed_target | No | ||
| expected_tool_target | No | ||
| preserve_temperatures | No | ||
| expected_chamber_target | No |