How to properly pause Octoprint to change filament manualy

How to properly pause Octoprint to change filament manualy

Clicking on Pause in Octoprint  stops the 3d print.  The printing head remains on the last position. If you want to change a filament you need to move the print head to a better position. In standard settings, you don’t have a chance to resume the print successfully. The print head doesn’t return to the last position automatically.

To be able to resume printing successfully,  you have enter some commands which will printer execute immediately after a click on Pause button and before the printer continues printing after a click on Resume button.

Go to the Octoprint settings  (wrench icon) -> GCODE Scripts. Into the input field “After print job is paused” enter  following code:

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

; retract filament of 0.8 mm up, move Z slightly upwards and 
G1 Z+5 E-0.8 F4500

; absolute XYZE

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

And into the “Before print job is resumed” input field

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

; prime nozzle
G1 E-0.8 F4500
G1 E0.8 F4500
G1 E0.8 F4500

; absolute E

; absolute XYZ

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

; WARNING!!! - use M83 or M82(exruder absolute mode) according what your slicer generates
M83 ; extruder relative mode

; 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 %}

Credits: code above is modified code from this Octoprint documetation  page. To find the page, go to Octoprint Documentation, then Features -> GCODE scripts ->Examples


Update:  September 21st 2018 11:20

This code was successfully tested on

  • Prusa MK2S
  • Prusa MK3
  • Octoprint Version 1.3.9
  •  Slic3r Prusa Edition 1.4.0 + win64

I am not able to test other 3d printers.

Bi-color cube printed via octoprint  by  pause/resume controls.

Share this post

Comments (53)

  • Kris

    I believe, thta in “Before print job is resumed” after “reset E” should be M82 instead of M83.

    2018-08-16 at 19:29
    • Rick

      Thank you so much, that mistake completely mess up my extruder. 😉 Thanks to the author nonetheless. 😀

      2018-09-20 at 21:22
    • yirco

      Hello Rick,
      I am sorry you have problems with the code I posted. I wouldn’t post something which I didn’t tested. Nevertheless, I did it again. I copied the code from the webpage into the Octoprint.
      Then I run a print. Paused the print. Changed the filament. Resumed. And again – pause, changed the filament, resume. Everything worked fine for me.
      Current test configuration:
      – Prusa MK2S with Firmware 3.1.0
      – Octoprint Version 1.3.9
      – Raspberry Pi 3
      – Slic3r Prusa Edition 1.4.0 + win64
      What is your configuration?
      Did you move the extruder during the pause manually?

      there is a switching from relative to absolute mode and back. It is possible that some switching is obsolete.
      Why do you recommend M82 instead of M83?

      2018-09-21 at 11:08
    • Murphy

      Hey yirco – I just printed benchy with 2 layers using your pause G-code and it worked perfectly with the latest versions of everything.
      – Prusa i3 MK3 Firmware 3.4.0
      – Octoprint Version 1.3.9
      – Rapsberry Pi B+
      – Slic3r Prusa Edition 1.41.0+linux64
      Unloading and loading filament was simple using the standard menu on the MK3. After a slight lag when pause is selected (probably due to cached commands) the print head rose up, went to a safe position and awaited manual filament change. It resumed printing right where it left off when the resume button was selected. Thanks for the great G-code!

      2018-09-23 at 4:14
    • yirco

      Hi Murphy,
      thanks for sharing the positive experience.
      You are right about the lag after pressing/clicking the Pause. The printer has to finish movements which are already cached. Otherwise, it wouldn’t be possible to determine exactly the position where to continue.
      best regards

      2018-09-24 at 12:19
    • Simon Barter

      Thank you Yirco for the code!

      Thank you Kris, after changing it to M82 instead of M83 it worked on my FLSUN QQ too!!!!

      2018-10-13 at 18:49
    • Andre Leduc

      On my Wanhao D9 300 it does work too with your solution to change to M82 instead of M83. Thanks.

      2018-12-29 at 12:43
    • Stephen C Williams

      Same for my Anet A8, works like a charm, very helpful

      2020-06-28 at 19:15
    • Stephen C, Williams

      What I actually had to do was change the M83 to M82 on the line directly below the warning to change that as required by the slicer, I am using Cura and it works perfectly. I had to reinstall it just now because I had to reinstall Octoprint on my Pi because it quit working. Thank you very much for making this easy and elegant fix.

      2021-03-20 at 14:37
  • noneya

    Thanks for the code, but reset E still has M83. Please update the snippet.

    2018-10-27 at 1:29
  • Steve

    Worked great on an Ender 3 with stock firmware. Thanks!

    2018-11-02 at 5:05
  • nigew

    I tried it, with M83, on an Anycubic i3 MEGA, Octoprint 1.3.9, Pi 3 B, Cura 3.6 without success. The position movements are excellent. Unfortunately the feed did not restart, even though the position and movement did. Happy to try again, and report back, if you want to suggest an alternative resume script.

    2018-12-07 at 9:58
    • yirco

      Hi nigew
      thanks for sharing.
      I am still not very sure why it on some printers work and not on others. I do believe that it depends on the slicer. I use Prusa printers and Sli3r Prusa Edition which sets extruder to relative mode on the beginning.

      Recently I’ve found this article about relative/absolute extruder mode. Look at the beginning of your GCODE generated by Cura. Is there M83 or M82 on the beginning? Before the printing continues you have to set it back to the mode of your slicer. I will appreciate if you try this and let us know about the result.
      best regards

      2018-12-07 at 12:04
  • yirco

    Hello guys,

    thank you all for sharing your experience. I suppose whether to use M83 or M82 in “before the print is resumed” depends on how the GCODE is generated. Each slicer can do it differently.
    Please let me know which slicer are you using and which M83/M82 works for you.
    If confirmed I will update the code with the comment.

    2018-12-07 at 12:19
    • tj

      please let me answer this,
      Cura uses M82 actually,
      I change M83 to M82 and works properly.

      you are correct, this depends on the slicer and need to adapt M82 or M83. Default cura is M82 (absolute).

      mine is ender 3 and cura for slicer.

      2018-12-31 at 0:03
    • richard

      hi tj

      can you help me out…
      i tried the code above and the hotend moves out of the way so i can change filament.
      but after resuming the print my hotend plunges into the print and keeps extruding.

      2019-02-24 at 15:37
    • Chris

      M83 drove my extruder at hyperspeed 🙁
      I was using slic3r and my printer is using Marlin if that matters (Anycubic Kossel Plus)

      2018-12-31 at 0:09
  • Robert

    Simplify3D, Ender 3, Octopi worked after switching to M82 per above… M83 resulted in over-extrusion. Thanks for the code! Once fixed, I was even able to turn off the printer for a long pause, leaving the Raspberry Pi powered, turn it back on and Octopi had the temp settings already on… after letting the temps ramp back to target, I was able to resume the print.

    I had been struggling with how to emulate the really useful resume print feature on the Ender firmware with Octopi. I think this handles most planned pauses, other than a surprise power outage.

    2018-12-28 at 23:41
    • Nacho

      Hi! How? When I try this (I turn off the Ender leaving Raspberry on), Octoprint loses the conection and the file in progress dissapear, no options to resume when I turn on the Ender and reconnect.

      2019-05-21 at 15:58
    • Kris

      It only looses connection if the PI cannot power the printer
      Make sure you are using a 2.1A power supply for your Pi

      2019-08-04 at 17:59
  • Carsten

    copy pasted the code while doing a job, this should work though.

    did a pause, and the head didn’t move, changed filament and resumed.
    Now that it’s still printing, it’s really slow.. approx 10 times slower.

    Using Anet A8, with latest marlin firmware, slice job is using sli3r.

    2018-12-31 at 23:14
  • Frode

    FLSUN cube, Cura, Octoprint 1.3.9 – Modifying to M82 worked like a charm.
    Thanks all

    2019-01-06 at 13:18
    • Carl Hilinski

      M82 is correct for a MP Maker Ultimate. With M83, the extruder doesn’t feed.

      2019-02-01 at 4:00
  • zaped212

    The M82 vs M83 debate is not about the printer, its about the slicer.
    If your slicer generates absolute extruder moves, then it should be:
    ; absolute E
    ; absolute XYZ
    Note I do not recommend the M82 after the G92 as some firmware may reset E to 0 when this happens.

    If your slicer genreate relative extruder modes then it sould be:

    ; absolute XYZ
    M83 ; extruder relative mode

    Once I tracked that down it started working for me.

    2019-02-14 at 5:00
  • richard

    can you help me out…
    i tried the code above and the hotend moves out of the way so i can change filament.
    but after resuming the print my hotend plunges into the print and keeps extruding.

    2019-02-24 at 15:38
    • yirco

      hi Richard

      what’s your printer and slicer?

      2019-02-24 at 15:42
  • Michael Scholz

    I’ve found that setting the park position of the extruded to something like 5,5 instead of 0,0 gives better results on printers with mechanical endstops because of the slight variation on triggering. If it’s relying on the stops to park at 0,0 then there can be some layer shift on resume. Parking with a software stop slightly away from the actual stops have given me perfect restarts on my ender 3 pro

    2019-03-28 at 4:42
    • Andy

      Thank you for this!

      2019-08-09 at 21:22
  • Filipe

    thanks. worked fine on my ender 3 using cura. just changed to M82 on the Warning part.

    2019-04-17 at 20:53
  • Digdogger

    works for me on Alfawise U20 and Simplify3D but warning with M82 because with M83 the motor will suddenly race and the filament goes out withe a crazy speed… Be carrefull!

    2019-05-08 at 19:02
  • da4throux

    That sounds really great, I need to test this 😀 Thanks a bunch.
    I was wondering: what kind of issue could I expect if I use this for a long pause (8 hours to allow quiet time during the night) ?
    Am I right assuming, that Octopi might lose connection or reset, and then nothing can be recovered ?
    Any advice on that would be great.

    2019-05-22 at 23:31
  • Anton

    I used M82 and it works like a charm! Genius! Thanks a lot for this piece of code! I injected the two code snippets during a running print on my Anycubic i3 Mega, with no test upfront, and it worked just perfect. Used it a couple of times more in further prints, I am really glad with this.
    Gives me a chance for some kind of basic multi color prints, and when running out of filament, I can now change.

    Just one little question. Would it be possible to tweak the code a little bit, so it pauses >>at the next z layer change<< ? That would make it even better and just perfect.
    Just asking, just in case. I find it very useful already.

    2019-06-12 at 17:51
  • Josh

    So how do you actually set it to pause at a given height, which would then run the “after pause” script and allow me to change the filament? Or, do I have to pause manually?

    2019-07-21 at 23:43
    • yirco

      Hi Josh,

      you have to stop it manually using Octoprint. Not on the printer itself! To pause automatically at a given height, try to find Octoprint plugin or prepare .gcode before print to stop at given height. I know Prusa has a description on their web pages. May be the newest Slicer Prusa Edition supports it too.


      2019-07-23 at 11:25
  • Stefan Foulis

    Awesome, thanks! This worked great. This saved a 10h print I was running. I was relieved to find out that it was possible to add the scripts in octoprint even though the print was already in progress.
    As mentioned in the snippet I checked if my slicer produces GCODE with M83 or M82 and adjusted the value.

    2019-09-23 at 8:58
  • phil

    you just saved 5h print
    gotta love that code for color change too thanks

    2019-10-13 at 23:15
  • DSpice

    You just saved a four day print for me. Tested on an Anycubic Chiron, Cura 4.3.0, Octoprint 1.3.12. Yes I know the Chiron has a filament sensor, but sadly its not recognized by Octoprint, so this code saved me a lot of frustration and a large reprint. Thank you!

    2019-11-12 at 17:34
  • DSpice

    Forgot to mention that with my configuration you do need to change to M82 from M83 after “Reset E” as mentioned above.

    2019-11-12 at 18:49
  • Robert

    Ender 3 Pro with TH3D unified firmware, EZABL, Cura 4.2.1, OctoPrint 1.3.11 running on OctoPi 0.16.0
    Changed M83 to M82 after “Reset E” as others have stated for Cura and this code worked perfectly for me. Saved a print that had been running for 15 hours and was going to be about 4 meters short on filament. Thanks!

    2019-11-18 at 4:12
    • Frank

      Which M83 did you change? Just the one after reset 3?

      2020-03-24 at 13:42
    • Joe

      I was wondering the same thing….I am already in to a print. Is is ONLY the M82 after “Reset E” or is it every instance you see in above code snippet. I used the cura slicer running M82 (looked in another Gcode myself) and am running octoprint from the pi on an Ender 3 Pro.

      2020-08-14 at 11:26
  • Clint D Hart

    Tested with the M82 code after ‘Reset E’. Great work!
    S3d slicer
    Ender 5 +
    OctoPrint 1.3.12

    2019-12-28 at 21:01
  • Michael Steinbach

    Thanks for the snippets Works excellent with the M82
    Artillery Sidewinder X1
    OctoPrint 1.3.16

    2020-01-19 at 18:00
  • Arjan Tel

    I am going to try this with M82 after “Reset E”
    Just one question, If I accidentally move the head while changing filament, will it still go to the correct position when resuming?
    Or should I add a “G28 X Y” somewhere? if so, where should I add that? before the “move back to pause position XYZ” ?

    Ender 3 with SKR mini E3 V1.2
    Cura 4.5
    Octoprint 1.3.11

    2020-04-21 at 9:08
    • yirco

      Hi Arjan,
      If you move the head manually, any printer (or let me know which one is:-) is able to recognize the heads absolute position.
      Some printers allow to move the head from a menu of the control computer. This doesn’t help neither, because the Octoprint doesn’t receive this information.

      Actually, all printers work internally with relative position. Motors receive number of ticks to move forward or backward. The commands M83 / M82 only say internally how the number of ticks are calculated. For absolute movement the number ticks is calculated from the stored absolute position. Stored absolute position is either calculated summing the relative movements or taken from the G-Code. The motor doesn’t send any information to the control computer if it reached the destination or not. If you move the head manually – control computer still believes that it is on the position last remembered.

      New printers come with trinamic drivers – units which directly control the current flowing to the motors. These units are able to give some kind of feedback about the real head (motor) movement. But not the real head position. And it is another story…

      hope it helps

      2020-04-24 at 10:34
  • Jason

    Thanks so much for this everyone, including the m82 command. I’ve got a print job running and am realizing that I’m about to run out of filament. Hopefully this saves the job, this community is great.

    2020-05-04 at 23:11
  • Laurent

    Thanks for this page.
    What is your code for “after print is cancelled”? Once can see a bit of it on the image.

    2020-06-07 at 18:49
  • Stephen C Williams

    I am using Cura 4.6.0 Octoprint 0.17.0 on an Anet A8 Sainsmart with a Raspberry Pi 3. M82 works for me, it still resumed with M83 but at a much slower rate. Thank you very much for this, it really helped me out.

    2020-06-28 at 19:19
  • Tim

    M82 worked great for me with:
    – Cura 4.6.2
    – Octoprint 1.4.2
    – Ender 5 Plus

    2020-08-16 at 8:53
  • Vincenzo

    Worked completely fine for me, with M82.

    Ender 3 v2
    Octoprint 1.5.1
    Cura 4.8

    2020-12-04 at 15:37
  • Doug

    Newbie here. Wow, I greatly appreciate this post. It’s exactly what I want to do.

    Quick question regarding the “WARNING”:

    I sliced with Cura. Line 12 of the outputted gcode says “M82 ;absolute extrusion mode”

    …So, I need to change M83 to M82 right?

    2021-01-17 at 5:34
    • yirco

      I’m not really sure what M82 on line 12 exactly is. But, this should be the way according to the earlier posts.
      Just make a test with a small thing before.

      2021-01-17 at 18:03

Leave a Reply