Jump to content
UltiMaker Community of 3D Printing Experts

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.3 stable released
        In this stable release, Cura 5.3 achieves yet another huge leap forward in 3D printing thanks to material interlocking! As well as introducing an expanded recommended print settings menu and lots of print quality improvements. Not to mention, a whole bunch of new printer profiles for non-UltiMaker printers!
          • Thanks
          • Like
        • 21 replies
      • Here it is. The new UltiMaker S7
        The UltiMaker S7 is built on the success of the UltiMaker S5 and its design decisions were heavily based on feedback from customers.
         
         
        So what’s new?
        The obvious change is the S7’s height. It now includes an integrated Air Manager. This filters the exhaust air of every print and also improves build temperature stability. To further enclose the build chamber the S7 only has one magnetically latched door.
         
        The build stack has also been completely redesigned. A PEI-coated flexible steel build plate makes a big difference to productivity. Not only do you not need tools to pop a printed part off. But we also don’t recommend using or adhesion structures for UltiMaker materials (except PC, because...it’s PC). Along with that, 4 pins and 25 magnets make it easy to replace the flex plate perfectly – even with one hand.
         
        The re-engineered print head has an inductive sensor which reduces noise when probing the build plate. This effectively makes it much harder to not achieve a perfect first layer, improving overall print success. We also reversed the front fan direction (fewer plastic hairs, less maintenance), made the print core door magnets stronger, and add a sensor that helps avoid flooding.
         

         
        The UltiMaker S7 also includes quality of life improvements:
        Reliable bed tilt compensation (no more thumbscrews) 2.4 and 5 GHz Wi-Fi A 1080p camera (mounted higher for a better view) Compatibility with 280+ Marketplace materials Compatibility with S5 project files (no reslicing needed) And a whole lot more  
        Curious to see the S7 in action?
        We’re hosting a free tech demo on February 7.
        It will be live and you can ask any questions to our CTO, Miguel Calvo.
        Register here for the Webinar
          • Like
        • 18 replies
      • UltiMaker Cura Alpha 🎄 Tree Support Spotlight 🎄
        Are you a fan of tree support, but dislike the removal process and the amount of filament it uses? Then we would like to invite you to try this special release of UltiMaker Cura. Brought to you by our special community contributor @thomasrahm
         
        We generated a special version of Cura 5.2 called 5.3.0 Alpha + Xmas. The only changes we introduced compared to UltiMaker Cura 5.2.1 are those which are needed for the new supports. So keep in mind, this is not a sneak peek for Cura 5.3 (there are some really cool new features coming up) but a spotlight release highlighting this new version of tree supports.  
          • Like
        • 22 replies
    ×
    ×
    • Create New...