Closed kartchnb closed 1 year ago
Rules Number One : if it's not broken don't fix it. For most of the scripts as the position of the line refers to a layer number and as these lines are unique for a layer or as we have most of the times only one Fan or Temp instruction by layer, I think it is not necessary to change the original code.
But for some of my scripts your coding is much more interesting and I will use your method in the future.
Thanks for these suggestions.
That's a really good rule... I would avoid a LOT of problems if I remembered that in the future.
Cheers!
I so much appreciate your help and advice and I wanted to share some changes I've found useful when developing my plugin. Feel free to ignore this if it's not useful for you.
Consider using Python's
enumerate
method to iterate through the gcode.For example, you can simplify this code (taken from your RetractTower.py file):
To this:
I worry that the original code could fail if there are duplicate lines in a layer. If this were to happen, the
line_index=lines.index(line)
command would return the index of the first line, which may not be correct. Theenumerate
function doesn't have this problem. It returns the correct line_index AND the line itself as it iterates.Ignore the user-specified "end" code
As you know, Cura lets the user provide their own "start" and "end" code that are automatically inserted into the gcode. I ran into a problem when my post-processing included the "end" code during post-processing, so now I'm ignoring it.
You're already ignoring the user's "start" code by skipping the first two layers in the gcode, but you may want to also ignore the last two layers. It looks like the second-to-last layer is the user's "end" code and the last layer just contains comments inserted by Cura.