G-code snippets for pause/resume with octoprint?  

Marc Liyanage
Active Member

I recently asked about pausing prints in this thread:


With the workaround of using filament change instead of pause, I now get perfect results when I try to insert magnets or nuts mid-print.

Now I want to move over to using octoprint on a Raspberry Pi so I don't have to move the USB stick back and forth between my computer and my Prusa Mini, which is in another room.

The octoprint setup worked great right away. I am now trying to use octoprint's "@pause" dummy gcode. In PrusaSlicer I use the custom g-code at layer feature to insert @pause. That does pause the print, and I can resume it through octoprint's web UI.

The only problem is that the results are not as good as what I got with the USB stick route and the filament change command. With just the @pause command, the problem is that the hot nozzle stays in place and melts whatever area of the print it's at.

So now I am trying to add two G-code snippets in octoprint's "after pause" and "after resume" scripts. I found a starting point in octoprint's docs here:


I pasted the code snippets below. The behavior is improved, the nozzle moves away from the print and to a location that lets me access the print area to insert things.

I have two problems:

1.) When the printer pauses and the nozzle moves up, it leaves behind a vertical strand of melted filament. I have to cut that off with a side-cutter. I thought the retraction for the E axis would prevent that.

2.) More importantly, when the print resumes, it seems that no filament is extruded. It just goes through the motions but no more filament is built up.

With the manual filament change method, I did not have either of these issues, so I know the printer is capable of cleanly pausing and resuming the print.

I tried various changes to the snippet, for example I tried to add a few mm more extrusion at resume than retraction at the pause (with a dwell and manual cleanup of the resulting gunk at the nozzle after the extrusion) to make sure the filament is really at the tip of the nozzle.

I tried to capture the issues in a video (sorry for the quality):

You can hopefully see that no filament is extruded when it resumes. Ignore the fact that it's a bit messy because I didn't clean the nozzle this time and cut off the extra vertical strand, I did that in other attempts and it made no difference. The main problem is that the nozzle doesn't seem to be extruding filament after the resume.

I wonder if anybody has experience with this and can help me come up with some g-code that does the right thing.



{% if pause_position.x is not none %}
; relative XYZE

; retract filament, move Z slightly upwards
G1 Z+5 E-5 F4500

; absolute XYZE

; move to a safe rest position, adjust as necessary
G1 X0 Y0
{% endif %}


{% if pause_position.x is not none %}
; relative extruder

; prime nozzle
G1 E-5 F4500
G1 E5 F4500
G1 E5 F4500

; absolute E

; absolute XYZ

; reset E
G92 E{{ pause_position.e }}

; move back to pause position XYZ
G1 X{{ pause_position.x }} Y{{ pause_position.y }} Z{{ pause_position.z }} F4500

; reset to feed rate before pause if available
{% if pause_position.f is not none %}G1 F{{ pause_position.f }}{% endif %}
{% endif %}


Posted : 04/07/2020 9:39 pm
atomleef liked
Estimable Member

Thanks for sharing, for beginner user as me I still quite not understand. I will try to understand it. 😄 

I also use swap color command, the nozzle is move away from the print some filament stuck to the nozzle and need to remove by hand as you said. Sorry for no solution yet just want to taking about problem. Good luck

Posted : 07/07/2020 2:44 am
Active Member

Thanks for sharing this code. It helps a lot.

It would be better if Prusa comes up with a codeless way of printing objects where we define an object using dimensions rather than the code.

Posted : 07/07/2020 10:56 am
New Member

Not sure if you ever got an answer but I suspect the reason  you are seeing no extrusion after resume is the use of the "M82" command to set absolute positioning on the extruder instead of "M83" for relative positioning which is what PrusaSlicer by default expects and requires. 

Posted : 29/10/2020 5:15 am
Active Member

Isn't the "change filament" routine the M600 command? At least thats the one that gets triggered from the filament sensor. So you could use this.

Posted : 29/10/2020 7:52 am

Please Login or Register