Jump to content
Ultimaker Community of 3D Printing Experts

Trying to add a gcode postprocessing exit to cura 2.4

Recommended Posts

OK, I have a printer that I usually keep plugged in to a Raspberry Pi.  It has a SSR that is controlled by M80 and M81.  I habitually power the printer's main power supply off after prints, automatically, while providing 5 volts through the USB.  This means that the arduino stays on and it can turn on the power supply.

So I stuck the M80 in the printer prefix and it didn't work.  It worked when I started the print and then ran to the printer front panel and turned on the power supply.  Examination of the gcode file showed that the printer prefix was not really a prefix, the warmup stuff was first, and, of course, nothing was going to warm up without the power supply.

So I thought, "OK, I will run a gcode exit to add M80 and G4 (to let the power settle) before continuing." Let me explain that I hate python, I know I am in the far minority but I think it is totally wrong headed.  But I have been a coder for 40+ years (retired) and so I can pretty much do any language with any structure. I started with a working python exit and came to this:


from ..Script import Scriptclass AddPowerOn(Script):def __init__(self):super().__init__()def getSettingDataString(self):return """{"name":"Add Power On Before Warming","key": "AddPowerOn","metadata": {},"version": 1,"settings": {}}"""def execute(self, data):for layer in data:index = data.index(layer)layer = "M80\nG4 P3000\n" + layerdata[index] = layer #Override the data of this layer with the modified datareturn databreakreturn data


(OK, that looks bad, sorry, I guess it is because the lines have extra newlines on them - they look good to me until I preview, sorry, the extra blanks are not there when I look at the file.)

Pretty simple, right?  No settings, no if.  It uses the same system as the script I cannibalized to peel out some data and it just sticks a couple of lines of gcode at the beginning.    I ran it separately to see that I had proper indentation (what a stupid idea, but you know I hate python) and I got the spacing to where it no longer gave me errors. Sigh.  But it would not compile because I guess you have to instantiate the class first, and then the children.  In any case

So when I put this into the c:\program files\cura 2.4\plugins\postprocessingplugin\scripts directory, it stops me from accessing any of the scripts there.  No error message I can see, I checked log and stderr, just an empty list when I try to display the list of exits.  I tried installing python, windows version, on my system, I tried restarting cura several times.  No joy.  

I take the exit I "wrote" out of the directory by renaming it to a non-py suffix.  And we now see the exits again.

So, what am I supposed to do to properly add this exit?  I have dug around, I don't see anything that I can relate to it.   Something I am doing is causing the system not to see any exits.  I did this under 15.6 or some such, a while back.  I see nowhere that the scripts are listed, I can only imagine that the directories are read to determine names.  I saw something about dependencies between exits but I don't think that is my issue.

Can anyone help with this?

Share this post

Link to post
Share on other sites

Not sure about 'exits', but I think the primary issue with your Python script is the version. It should be version 2, and I don't think you need the triple quotes on the return as well.

Here's a fixed version of your script: http://bitman.org/dahai/AddPowerOn.zip

I think the reason they call it Python is its very temperamental and will snap back and bite you if you do something wrong...

Hope this helps.

  • Like 1

Share this post

Link to post
Share on other sites

Instead of fixing your problem with a custom postprocessing script, let me try to fix the root of your problem.

The reason CuraEngine puts the bed/nozzle temperature commands in front of your start gcode is because your start gcode does not contain commands to heat the bed/nozzle. Make sure the following snippet is in the appropriate place in your start gcode:


M190 S{material_bed_temperature} ; wait for bed tempM109 S{material_print_temperature} ; wait for extruder temp


This will make sure CuraEngine does not have to add it by itself, and you can put your M80 and G4 before the temperature commands.

Edited by Guest

Share this post

Link to post
Share on other sites

For anyone who cares, this is the fixed script:

#!/usr/bin/env python
from ..Script import Script
class AddPowerOn(Script):
   def __init__(self):
   def getSettingDataString(self):
       return {
           "name":"Add Power On Before Warming",
           "key": "AddPowerOn",
           "metadata": {},
           "version": 2,
           "settings": {}
   def execute(self, data):
       for layer in data:
           index = data.index(layer)
           layer = "M80\nG4 P3000\n" + layer
           data[index] = layer #Override the data of this layer with the modified data
           return data
       return data

Edited by Guest
Mistakenly duplicated content.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Our picks

    • Ultimaker Cura | a new interface
      We're not only trying to always make Ultimaker Cura better with the usual new features and improvements we build, but we're also trying to make it more pleasant to operate. The interface was the focus for the upcoming release, from which we would already like to present you the first glance. 
        • Like
      • 121 replies
    • "Back To The Future" using Generative Design & Investment Casting
      Designing for light-weight parts is becoming more important, and I’m a firm believer in the need to produce lighter weight, less over-engineered parts for the future. This is for sustainability reasons because we need to be using less raw materials and, in things like transportation, it impacts the energy usage of the product during it’s service life.
        • Like
      • 12 replies

Important Information

Welcome to the Ultimaker Community of 3D printing experts. Visit the following links to read more about our Terms of Use or our Privacy Policy. Thank you!