-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgcode_edit.py
More file actions
18 lines (17 loc) · 842 Bytes
/
gcode_edit.py
File metadata and controls
18 lines (17 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env python3
import fileinput
import re
import sys
"Usage gcode_edit.py gcodeprogram.gcode axis offset -- gcode_edit.py program.gcode X -25"
with fileinput.FileInput(sys.argv[1], inplace=True, backup='.bak') as file:
for line in file:
elements = re.split(' ', line)
for i in range(len(elements)):
if (elements[i].find(str(sys.argv[2])) != -1):
axis_integer=round(float((elements[i])[1:])-float(sys.argv[3])),4)
"This assumes that your orgin is the lower left of the table. If it is the center of the table comment out these two lines."
if (axis_integer < 0):
axis_integer=0
elements[i]=(str(sys.argv[2])+str(axis_integer))
fixed_line = ' '.join(elements)
print(fixed_line, end='')