From 1be9f3ac35e45af4c8a8fcfe0a3050f2d77cb577 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Thu, 6 Jul 2017 11:02:36 -0500 Subject: [PATCH] Path: fix bug in gcode importer. Wouldn't handle lines with only a line number --- src/Mod/Path/PathScripts/post/example_pre.py | 28 ++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Mod/Path/PathScripts/post/example_pre.py b/src/Mod/Path/PathScripts/post/example_pre.py index fd06fb32ed..87d4b38ea9 100644 --- a/src/Mod/Path/PathScripts/post/example_pre.py +++ b/src/Mod/Path/PathScripts/post/example_pre.py @@ -34,6 +34,14 @@ from GCode. import os import Path import FreeCAD +import PathScripts.PathLog as PathLog + +if True: + PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) + PathLog.trackModule(PathLog.thisModule()) +else: + PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) + # to distinguish python built-in open function from the one declared below if open.__module__ == '__builtin__': @@ -41,6 +49,7 @@ if open.__module__ == '__builtin__': def open(filename): + PathLog.track(filename) "called when freecad opens a file." docname = os.path.splitext(os.path.basename(filename))[0] doc = FreeCAD.newDocument(docname) @@ -49,6 +58,7 @@ def open(filename): def insert(filename, docname): "called when freecad imports a file" + PathLog.track(filename) gfile = pythonopen(filename) gcode = gfile.read() gfile.close() @@ -61,12 +71,14 @@ 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 = "" lastcommand = None - + print (lines) + for l in lines: # remove any leftover trailing and preceding spaces l = l.strip() @@ -75,8 +87,14 @@ def parse(inputstring): continue if l[0].upper() in ["N"]: # remove line numbers - l = l.split(" ",1)[1] - if l[0] in ["(","%","#"]: + l = l.split(" ",1) + if len(l)>=1: + l = l[1] + else: + continue + + + if l[0] in ["(","%","#",";"]: # discard comment and other non strictly gcode lines continue if l[0].upper() in ["G","M"]: @@ -92,7 +110,7 @@ def parse(inputstring): elif lastcommand: # no G or M command: we repeat the last one output += lastcommand + " " + l + "\n" - + print("done preprocessing.") return output