Created
May 2, 2016 18:40
-
-
Save imrahil/0e39a7f44557f93b01ff5c8c7e43fe69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
import math, random, copy, sys | |
inputfile = "" | |
outputfile = "" | |
for i in range(len(sys.argv)): | |
if i == 0: | |
continue | |
elif inputfile == "": | |
inputfile = sys.argv[i] | |
elif outputfile == "": | |
outputfile = sys.argv[i] | |
if inputfile == "": | |
inputfile = raw_input("Input File: ") | |
outputfile = raw_input("Output File: ") | |
elif outputfile == "": | |
# This assumes that any path specification is free of periods | |
outputfile = inputfile.split(".")[0] + "-info.gcode" | |
try: | |
f = open(inputfile) | |
try: | |
f2 = open(outputfile, "w") | |
except: | |
print "File " + outputfile + " failed to open. Exiting." | |
quit() | |
except: | |
print "File " + inputfile + " failed to open. Exiting." | |
quit() | |
layer=0 | |
layercount=0 | |
for rawline in f: | |
line=rawline.upper() | |
line=line.strip() | |
chunks=line.split(";")[0].split(" ") | |
if chunks[0]=="M117": | |
layercount += 1 | |
# print "layer: " + str(layer) + " / " + str(layercount) | |
print "Layer count: " + str(layercount) | |
f.seek(0) | |
for rawline in f: | |
line=rawline.upper() | |
line=line.strip() | |
chunks=line.split(";")[0].split(" ") | |
stuff={} | |
if chunks[0]=="M117": | |
layer += 1 | |
rawline = "M117 Layer " + str(layer) + " of " + str(layercount) + "\r" | |
f2.write(rawline) | |
f2.write("M117 Print complete!") | |
f2.close() | |
print "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment