Jump to content

A bunch of things PostProcessingPlugIns and debug


Recommended Posts

Posted · A bunch of things PostProcessingPlugIns and debug

When I began to work on PostProcessingPlugIns, it was a pain as there is no way to debug the script

No message, even sometimes my plug in not appearing in the list.


So I tried to install a standalone Python with debugger and work on it. This is what this post is about ...


I Have windows 7 64 bit, Cura 4.0 and Python 3.7 with IDLE


I build two configuration, one for the Cura script folder (for me in \AppData\Roaming\cura\4.0\scripts) and one in the script folder for Cura in Python (for me in \AppData\Local\Programs\Python\Python37-32\Scripts\Cura)


The basic logic is I create a superClass MyScript derived from tje script class of Cura, in which I put all the stuff to manage the scrip, leaving only in the script the variables and settings definition, and the formulas working to modify the GCode

It gives a feel & look for all the scripts, gives more information to the user in the GCode, and also manage the way to debug a script in Python


To debug in Python, you have the same superclass, a DEBUG_SCRIPT script to prepare the GCode for debugging, a tKinter Window class to run the script in python, and a mini script class having only the functions necessary to do like the one in Cura (but only for debugging purpose)


In the file below you'll find the two configuration you have only t extract them in the corresponding folders and then restart Cura and deiscover ...


As PostProcessingplugIns you'll find


1 DEBUG_SCRIPT : to prepare the GCode for debugging a new script

2 Comment : a script only to add a comment a the begining of the Gcode (you can use it several times in one slicing process)

3 Remaining printing Time : to send to the printer LCD at each layer the time remaining up to the end

4 Lower Tiny holes printinting speed on 1st layer : to hav a better printing without filament dragging effect

5 LiftHead without annoying too large Z movement : to have a better quality for small layers


Now look at this scenario :




I insert all these scripts (number 1 to 8 to follow the result below), a few of them which will give an error that is handled


Here are the resulting pieces of GCode


1) Start of GCode



GCode during the 1st layer within a tiny Hole, speed reduced from 1800 to 600




end of a layer with information from several scripts




Now if I want to debug a script on the resulting Gcode file i have a the end of the slicing in Cura to save it in the IDLE scripts for Cura folder.


Then I go in Python's IDLE and run a script I want to debug


It appears a window to select the GCode file



Then the next window is to enter the settings for the script



if I close the window, result in IDLE




Or if I enter the correct params




If there were errors the IDLE debugger will give you a lot of information to modify your script

InCuraScriptFojder.zip InIDLEscriptFolderForCura.zip

  • Like 1
Link to post
Share on other sites

Posted · A bunch of things PostProcessingPlugIns and debug

Have you looked at iPython/Jupyter?

iPython is basically the original repl on steroids and the "console" versions of it are a great way to merge IDLE and the REPL in one shot. Jupyter, originally called IPython Notebook - takes it a step further and abstracts the backing interpreter so that it can be housed in a web-service, where a "notebook" is basically a webified version of a repl with "cells" containing blocks of code that you can tweak/re-execute, iterate on. The back-end abstraction they called "a kernel" and because of this they're able to actually service pretty much any programming language as a back-end, it's even possible to have different languages in different cells.

It brings a lot else to the table, including "magics" - additional commands that start with "%", e.g. %time and %timeit for benchmarking, "?" and "??" for querying objects/modules etc, ? being an abbreviation for "help(...)" and "??" giving generally better info,

There are various debugger features too, but for me the most convenient is "%load_ext autoreload" and "%autoreload 2" so that as I make source-file changes they get auto-reloaded in the running interpreter.

  • Link to post
    Share on other sites

    Posted · A bunch of things PostProcessingPlugIns and debug


    - "def __init__(self) -> None:"
    init doesn't return None, it actually doesn't return anything, so at some point having the "-> None" will break your code.

    - if you make your function-entry comments into strings, python will automatically use them as the function's __doc__ property, so that they are documented by help(function_name, and will the life of anyone who looks at your code as well as your own a lot easier 🙂

    > ipython
    Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)]
    Type 'copyright', 'credits' or 'license' for more information
    IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.
    In [1]: def getSettingDataString(self):
       ...:     """ You may either use the normal getSettingDataString function or the getSettingDataStringWithInfo
       ...:         the latter will add a comment setting in which you can enter any relevant information
       ...:         you want to insert at the beginning of the GCode file """
       ...:     pass
    In [2]: help(getSettingDataString)
    Help on function getSettingDataString in module __main__:
        You may either use the normal getSettingDataString function or the getSettingDataStringWithInfo
        the latter will add a comment setting in which you can enter any relevant information
        you want to insert at the beginning of the GCode file
    In [3]:

    If you'd like to experiment with gcode without always having to remember the gcode names ... it's very preliminary, I've only been hacking at it for a few hours: https://github.com/kfsone/pymcode. If you have a UM3, there's a "ultimaker3.py" script you can run that drops you into an ipython repl with "um3" configured as a connection to your printer and "ops" having all of the command aliases. Or you can then type "repl()" and it will go into a mode where you can basically either type '"M104' to send raw gcode, or you can just use the command names:


    Cmd> "M105
    Cmd> set_bedtemp 65
    Cmd> "T0
    Cmd> set_hotendtemp 200
    Cmd> wait_hotendtemp 190
    Cmd> go

    There's a "help" command to list the repl commands.



  • 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

      • 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.
          • Like
        • 0 replies
      • Ultimaker Cura 5.6 stable released
        Cura now supports Method series printers!
        A year after the merger of Ultimaker and MakerBotQQ, we have unlocked the ability for users of our Method series printers to slice files using UltiMaker Cura. As of this release, users can find profiles for our Method and Method XL printers, as well as material profiles for ABS-R, ABS-CF, and RapidRinse. Meaning it’s now possible to use either Cura or the existing cloud-slicing software CloudPrint when printing with these printers or materials
        • 48 replies
    • Create New...