Jump to content

Trying to add a gcode postprocessing exit to cura 2.4


brzasshopper

Recommended Posts

Posted · Trying to add a gcode postprocessing exit to cura 2.4

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?

  • Link to post
    Share on other sites

    Posted · Trying to add a gcode postprocessing exit to cura 2.4

    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
    Link to post
    Share on other sites

    Posted (edited) · Trying to add a gcode postprocessing exit to cura 2.4

    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
  • Link to post
    Share on other sites

    Posted · Trying to add a gcode postprocessing exit to cura 2.4

    Both of these solutions work, thanks. I put in the triple quotes because my example had them. Sigh. It never occurred to me that if I put the warming commands in that CURA would see that and not add them.

  • Link to post
    Share on other sites

    Posted (edited) · Trying to add a gcode postprocessing exit to cura 2.4

    For anyone who cares, this is the fixed script:

    #!/usr/bin/env python
    from ..Script import Script
    class AddPowerOn(Script):
       def __init__(self):
           super().__init__()
       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
               break
           return data
    

    Edited by Guest
    Mistakenly duplicated content.
  • Link to post
    Share on other sites

    Posted · Trying to add a gcode postprocessing exit to cura 2.4

    I am still wondering what a "gcode exit" is though. I guess you mean "gcode script" or "gcode plugin", but I am curious how you get from the word "exit" to the word "plugin".

  • 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 5.7 stable released
        Cura 5.7 is here and it brings a handy new workflow improvement when using Thingiverse and Cura together, as well as additional capabilities for Method series printers, and a powerful way of sharing print settings using new printer-agnostic project files! Read on to find out about all of these improvements and more. 
         
          • Like
        • 18 replies
      • S-Line Firmware 8.3.0 was released Nov. 20th on the "Latest" firmware branch.
        (Sorry, was out of office when this released)

        This update is for...
        All UltiMaker S series  
        New features
         
        Temperature status. During print preparation, the temperatures of the print cores and build plate will be shown on the display. This gives a better indication of the progress and remaining wait time. Save log files in paused state. It is now possible to save the printer's log files to USB if the currently active print job is paused. Previously, the Dump logs to USB option was only enabled if the printer was in idle state. Confirm print removal via Digital Factory. If the printer is connected to the Digital Factory, it is now possible to confirm the removal of a previous print job via the Digital Factory interface. This is useful in situations where the build plate is clear, but the operator forgot to select Confirm removal on the printer’s display. Visit this page for more information about this feature.
        • 0 replies
    ×
    ×
    • Create New...