Skip to content

Instantly share code, notes, and snippets.

@AdoHaha
Created May 17, 2016 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdoHaha/a2d52f7974f47ab0a26eddebd1103e56 to your computer and use it in GitHub Desktop.
Save AdoHaha/a2d52f7974f47ab0a26eddebd1103e56 to your computer and use it in GitHub Desktop.
import re
import sys
filename = sys.argv[-1]
gcode = open(filename)
data = gcode.read()
def replace(match):
match = match.group(2)
#print match
serious_zaok=str(round(float("0."+match),5))
print match
print "zaok",serious_zaok[2:7]
return "."+serious_zaok[2:7]
return "." + match[0:4]
pattern = re.compile(r"([.])([0-9]+)")
output = re.sub(pattern, replace, data)
output = re.sub(r'T0 M6',r'(TO M6) (gives error on grbl)',output)
new_filename = filename[:-3] + '-truncated.nc'
file = open(new_filename, "w")
file.write("(Modified by metric-gcode-truncator. Intended for use in absolute mode. Incremental mode may cause errors.)")
file.write(output)
file.close()
gcode.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment