forked from Ghostkeeper/X3GWriter
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconvert_gcode.py
More file actions
executable file
·42 lines (30 loc) · 1.04 KB
/
convert_gcode.py
File metadata and controls
executable file
·42 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
import sys
import os
import argparse
parser = argparse.ArgumentParser(description="""
convert a RepRap/Marlin flavor GCode file to a Machinekit/Velocity-Extrusion flavor GCode file
""")
parser.add_argument('-i', '--input', help='Input file', required=True)
parser.add_argument('-o', '--ouput', help='Output file', default=None)
args = parser.parse_args()
sys.path = [os.path.abspath(os.path.dirname(__file__))] + sys.path
from converter.gcode2ngc import GCode2Ngc
from converter.ngc2ve import Ngc2Ve
input_name = args.input
(path, _) = os.path.splitext(input_name)
output_name = '%s.ngc' % path
print('converting %s -> %s' % (input_name, output_name))
input_file = open(input_name, 'rt')
output_file = open(output_name, 'wt')
gcode_list = input_file.readlines() # fix maybe
input_file.close()
# TODO: add prefix
gcodeConverter = GCode2Ngc()
veConverter = Ngc2Ve()
gcodeConverter.process(gcode_list)
veConverter.process(gcode_list)
for gcode in gcode_list:
output_file.write(gcode)
# TODO: add postfix
output_file.close()