the beginning
This commit is contained in:
parent
d66c7d7340
commit
069df18859
13
Pipfile
Normal file
13
Pipfile
Normal file
@ -0,0 +1,13 @@
|
||||
[[source]]
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
click = "*"
|
||||
pudb = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[requires]
|
||||
python_version = "3.9"
|
50
Pipfile.lock
generated
Normal file
50
Pipfile.lock
generated
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "e9f54d81978ae2edab8cc80ea40118ed24f519a6e62f68a7fcdfa94083086e5a"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.9"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"click": {
|
||||
"hashes": [
|
||||
"sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a",
|
||||
"sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==7.1.2"
|
||||
},
|
||||
"pudb": {
|
||||
"hashes": [
|
||||
"sha256:e8f0ea01b134d802872184b05bffc82af29a1eb2f9374a277434b932d68f58dc"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2019.2"
|
||||
},
|
||||
"pygments": {
|
||||
"hashes": [
|
||||
"sha256:ccf3acacf3782cbed4a989426012f1c535c9a90d3a7fc3f16d231b9372d2b716",
|
||||
"sha256:f275b6c0909e5dafd2d6269a656aa90fa58ebf4a74f8fcf9053195d226b24a08"
|
||||
],
|
||||
"markers": "python_version >= '3.5'",
|
||||
"version": "==2.7.3"
|
||||
},
|
||||
"urwid": {
|
||||
"hashes": [
|
||||
"sha256:588bee9c1cb208d0906a9f73c613d2bd32c3ed3702012f51efe318a3f2127eae"
|
||||
],
|
||||
"version": "==2.1.2"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
}
|
142291
file.gcode
Normal file
142291
file.gcode
Normal file
File diff suppressed because it is too large
Load Diff
142291
file_modified.gcode
Normal file
142291
file_modified.gcode
Normal file
File diff suppressed because it is too large
Load Diff
66
gce.py
Normal file
66
gce.py
Normal file
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# usage gce mirror --axis x translate --y -200 file.gcode
|
||||
# usage gce
|
||||
arg_mirror_axis = 'y'
|
||||
arg_translation=[200, 0, 0]
|
||||
arg_file_path='file.gcode'
|
||||
|
||||
|
||||
from os import remove, rename
|
||||
from re import sub, findall, match, IGNORECASE
|
||||
# import click
|
||||
|
||||
|
||||
# modify_instructions = 'G0, G1, G2, G3, G90, G91, S, F, M3, M4'.split(', ')
|
||||
modify_instructions = '(G(0|1|2|3|90|91)|S|F|M(3|4))'
|
||||
temp_file_path = '.file.gcode.tmp'
|
||||
out_file_path = 'file_modified.gcode'
|
||||
|
||||
# @click.command()
|
||||
# @click.option('--axis', default='x', help='mirror axis')
|
||||
# @click.argument('mirror')
|
||||
def mirror(instruction, axis='Y'):
|
||||
return instruction.replace(axis, f'{axis}-')
|
||||
|
||||
|
||||
def translate(instruction, translation=[0, 0, 0]):
|
||||
pattern = 'X[-0-9.]+'
|
||||
x = findall(pattern, instruction, IGNORECASE)
|
||||
if not x:
|
||||
return instruction
|
||||
try:
|
||||
x = float(x[0][1:])
|
||||
except ValueError:
|
||||
return instruction
|
||||
x = round(x + translation[0], 3)
|
||||
return sub(pattern, f'X{x}', instruction, IGNORECASE)
|
||||
|
||||
|
||||
with open(arg_file_path, 'r') as gcode:
|
||||
|
||||
try:
|
||||
remove(temp_file_path)
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
with open(temp_file_path, 'w') as tmp_gcode:
|
||||
|
||||
instructions = gcode.readlines()
|
||||
instructions_length = len(instructions)
|
||||
instructions_count = 0
|
||||
for instruction in instructions:
|
||||
|
||||
instructions_count += 1
|
||||
print(f'\rparsing instruction {instructions_count}/{instructions_length})',
|
||||
end='')
|
||||
instruction = instruction.strip()
|
||||
if match(modify_instructions, instruction, IGNORECASE):
|
||||
# if any(map(instruction.__contains__, modify_instructions)):
|
||||
|
||||
# import pudb; pudb.set_trace()
|
||||
instruction = mirror(instruction, axis=arg_mirror_axis)
|
||||
instruction = translate(instruction, translation=arg_translation)
|
||||
tmp_gcode.write(f'{instruction}\n')
|
||||
|
||||
rename(temp_file_path, out_file_path)
|
142291
mirror-y.gcode
Normal file
142291
mirror-y.gcode
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user