From 858039639e33fb2fce0002cca5e8f620c82d48c5 Mon Sep 17 00:00:00 2001 From: Georgiy Bondarenko <69736697+nehilo@users.noreply.github.com> Date: Mon, 5 Oct 2020 23:57:19 +0500 Subject: Add files via upload --- CuraPlugin_AddPctComplete.py | 67 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 CuraPlugin_AddPctComplete.py diff --git a/CuraPlugin_AddPctComplete.py b/CuraPlugin_AddPctComplete.py new file mode 100644 index 0000000..d8ae89c --- /dev/null +++ b/CuraPlugin_AddPctComplete.py @@ -0,0 +1,67 @@ +#Name: Display Build Progress +#Info: During printing, display the percentage of build complete +#Depend: GCode +#Type: postprocess + +# Written by Peter Monaco, Dec 22, 2015 +# Drop in your /plugins directory + +import re + +### Un-comment these lines to use as a standalone script: +#import sys +#inputFilename = sys.argv[1] +#outputFilename = "tmpout" + +### Comment-out these lines to make it a standalone script: +inputFilename = filename +outputFilename = filename + +# returns a float, or -1 if no Extrusion value is present in that line +def findEValueInLine(line): + tokens = line.split() + for token in tokens: + if (token.startswith("E")): + floatVal = token[1:(len(token))] + try: + v = float(floatVal); + if (v > 0): + return v + except ValueError: + continue + return -1 + +def findLargestExtrusionValue(lines): + for line in reversed(lines): + eVal = findEValueInLine(line) + #print "Found {} in {}".format(eVal, line) + if (eVal > 0): + return eVal + return 1 + + + +with open(inputFilename, "r") as f: + lines = f.readlines() + +# Find the largest extrusion value in the file, searching backward from the end +# We will compute percent-complete as a fraction of total extrusion + +maxExtrusion = findLargestExtrusionValue(lines) +#print "Found max extrusion to be: {}".format(maxExtrusion) + + +lastPct = 0 +with open(outputFilename, "w") as f: + for line in lines: + f.write(line) + eValue = findEValueInLine(line) + if (eValue > 0): + # compute the % + pct = int(100.0 * eValue / maxExtrusion) + if (pct > lastPct and pct < 100): + f.write("M73 P{}\n".format(pct)) + lastPct = pct + + + -- cgit v1.2.3