aboutsummaryrefslogtreecommitdiff
path: root/CuraPlugin_AddPctComplete.py
diff options
context:
space:
mode:
authorGeorgiy Bondarenko <69736697+nehilo@users.noreply.github.com>2020-10-05 21:57:19 +0300
committerGitHub <noreply@github.com>2020-10-05 21:57:19 +0300
commit858039639e33fb2fce0002cca5e8f620c82d48c5 (patch)
treec4505c3f3ed644c91e143feffbfd96723dd0d224 /CuraPlugin_AddPctComplete.py
parent98482c76b28f7a45e216eb253fe99bf2309f2c50 (diff)
downloadkp3s-marlin-858039639e33fb2fce0002cca5e8f620c82d48c5.tar.xz
kp3s-marlin-858039639e33fb2fce0002cca5e8f620c82d48c5.zip
Add files via upload
Diffstat (limited to 'CuraPlugin_AddPctComplete.py')
-rw-r--r--CuraPlugin_AddPctComplete.py67
1 files changed, 67 insertions, 0 deletions
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 <CuraInstallation>/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
+
+
+