diff --git a/src/Mod/Path/CMakeLists.txt b/src/Mod/Path/CMakeLists.txt index b30ca0e472..098bb114dd 100644 --- a/src/Mod/Path/CMakeLists.txt +++ b/src/Mod/Path/CMakeLists.txt @@ -128,6 +128,7 @@ SET(PathScripts_post_SRCS PathScripts/post/comparams_post.py PathScripts/post/dynapath_post.py PathScripts/post/example_pre.py + PathScripts/post/gcode_pre.py PathScripts/post/grbl_post.py PathScripts/post/jtech_post.py PathScripts/post/linuxcnc_post.py diff --git a/src/Mod/Path/PathScripts/PathCustom.py b/src/Mod/Path/PathScripts/PathCustom.py index a07343731c..4be7e94314 100644 --- a/src/Mod/Path/PathScripts/PathCustom.py +++ b/src/Mod/Path/PathScripts/PathCustom.py @@ -52,27 +52,23 @@ class ObjectCustom: return None def execute(self, obj): + commands = [] + newPath = Path.Path if obj.Gcode: - s = "" for l in obj.Gcode: - s += str(l) - if s: - path = Path.Path(s) - if obj.OperationPlacement: - for x in range(len(path.Commands)): - if path.Commands[x].Name in movecommands: - base = copy(obj.Placement.Base) - new = path.Commands[x] - if 'X' not in path.Commands[x].Parameters: - base[0] = 0.0 - if 'Y' not in path.Commands[x].Parameters: - base[1] = 0.0 - if 'Z' not in path.Commands[x].Parameters: - base[2] = 0.0 - new.Placement.translate(base) - path.deleteCommand(x) - path.insertCommand(new, x) - obj.Path = path + newcommand=Path.Command(str(l)) + if newcommand.Name in movecommands and obj.OperationPlacement: + if 'X' in newcommand.Parameters: + newcommand.x += obj.Placement.Base.x + if 'Y' in newcommand.Parameters: + newcommand.y += obj.Placement.Base.y + if 'Z' in newcommand.Parameters: + newcommand.z += obj.Placement.Base.z + + commands.append(newcommand) + newPath.addCommands(commands) + + obj.Path = newPath class CommandPathCustom: diff --git a/src/Mod/Path/PathScripts/post/gcode_pre.py b/src/Mod/Path/PathScripts/post/gcode_pre.py index 1ec9aaa702..0ec421b521 100644 --- a/src/Mod/Path/PathScripts/post/gcode_pre.py +++ b/src/Mod/Path/PathScripts/post/gcode_pre.py @@ -78,13 +78,11 @@ def insert(filename, docname): def parse(inputstring): "parse(inputstring): returns a parsed output string" print("preprocessing...") - print(inputstring) PathLog.track(inputstring) # split the input by line lines = inputstring.split("\n") - output = "" + output = [] #"" lastcommand = None - print(lines) for lin in lines: # remove any leftover trailing and preceding spaces @@ -96,7 +94,7 @@ def parse(inputstring): # remove line numbers lin = lin.split(" ", 1) if len(lin) >= 1: - lin = lin[1] + lin = lin[1].strip() else: continue @@ -105,7 +103,8 @@ def parse(inputstring): continue if lin[0].upper() in ["G", "M"]: # found a G or M command: we store it - output += lin + "\n" + #output += lin + "\n" + output.append(lin) # + "\n" last = lin[0].upper() for c in lin[1:]: if not c.isdigit(): @@ -115,10 +114,10 @@ def parse(inputstring): lastcommand = last elif lastcommand: # no G or M command: we repeat the last one - output += lastcommand + " " + lin + "\n" + output.append(lastcommand + " " + lin) # + "\n" print("done preprocessing.") return output -print(__name__ + " gcode preprocessor loaded.") +print(__name__ + " gcode preprocessor loaded.") \ No newline at end of file