Need to make Cancel Print work better for Prusa, MMU

When I discover something is wrong and I need to abort and start over, I try to Cancel Print.
That leaves the printer in a bad state, with the hot nozzle touching something. I need to be quick and manually lift it using Octoprint. It also doesn't restore the setup to be ready to print reliably. It's still hot, and there's filament all the way through the MMU2 filament switch to the nozzle.
I'd like to hit Cancel Print, clean the print bed, and quickly start a new print.
I'm using a Prusa MK3S with MMU2.
Perhaps I'm missing something? Is there a better way to abort a print?

Hello @DaveGadgeteer!

You have to setup a script in OctoPrint for cancelling. I've done this and it works fine:

; Lift print head a bit
G91 ; relative pos
G1 Z5 ; Move print head up
G90 ; absolute pos
M702 C ; unload Filament
G28 X  ; Home X axis
;G4 ; wait
;M104 S0 ; turn off temperature
;M140 S0 ; turn off heatbed
M107 ; turn off fan
;G1 X0; home X axis
M84 ; disable motors

You put it here:

I left the temperatures on (M104/M140) to have a fast start over.
Actually this is the end sequence of a regular MMU gcode file.


Thank you very much!


THANK you for the solution to DaveGadgeteer's problem. I had the same exact problem and was frustrated when I had to cancel a print with my MK3S MMU2 setup.
I added your end codes (but I had it turn off the heaters and motors).
I was able to test it out when I had to cancel two print jobs over the weekend.
Both jobs were cancelled perfectly. (Unloaded the filament and moved the head away from the print job). PERFECT.

THANK YOU for explaining what needs to be done, AND for providing the actual code that I needed for my setup.