mirror of
				https://github.com/valentineus/kp3s-marlin.git
				synced 2025-11-04 01:59:44 +03:00 
			
		
		
		
	Add files via upload
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							98482c76b2
						
					
				
				
					commit
					858039639e
				
			
							
								
								
									
										67
									
								
								CuraPlugin_AddPctComplete.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								CuraPlugin_AddPctComplete.py
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user