From ae761583a66fb95e2f7abd5ac2bbaf693bbae427 Mon Sep 17 00:00:00 2001 From: Patrick F Date: Sat, 2 Jan 2021 21:37:32 +0100 Subject: [PATCH] Updated centroid post --- .../Path/PathScripts/post/centroid_post.py | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Mod/Path/PathScripts/post/centroid_post.py b/src/Mod/Path/PathScripts/post/centroid_post.py index 9c8408c9e3..1b4669b855 100644 --- a/src/Mod/Path/PathScripts/post/centroid_post.py +++ b/src/Mod/Path/PathScripts/post/centroid_post.py @@ -48,6 +48,7 @@ Arguments for centroid: --show-editor, --no-show-editor ... pop up editor before writing output(--show-editor) --feed-precision=1 ... number of digits of precision for feed rate. Default=1 --axis-precision=4 ... number of digits of precision for axis moves. Default=4 + --inches ... Convert output for US imperial mode (G20) ''' now = datetime.datetime.now() @@ -65,8 +66,9 @@ COMMAND_SPACE = " " LINENR = 100 # line number starting value # These globals will be reflected in the Machine configuration of the project -UNITS = "G20" # G21 for metric, G20 for us standard -UNIT_FORMAT = 'mm/min' +UNITS = "G21" # G21 for metric, G20 for us standard +UNIT_FORMAT = 'mm' +UNIT_SPEED_FORMAT = 'mm/min' MACHINE_NAME = "Centroid" CORNER_MIN = {'x': -609.6, 'y': -152.4, 'z': 0} # use metric for internal units CORNER_MAX = {'x': 609.6, 'y': 152.4, 'z': 304.8} # use metric for internal units @@ -125,6 +127,9 @@ def processArguments(argstring): global SHOW_EDITOR global AXIS_PRECISION global FEED_PRECISION + global UNIT_SPEED_FORMAT + global UNIT_FORMAT + global UNITS for arg in argstring.split(): if arg == '--header': @@ -147,6 +152,10 @@ def processArguments(argstring): AXIS_PRECISION = arg.split('=')[1] elif arg.split('=')[0] == '--feed-precision': FEED_PRECISION = arg.split('=')[1] + elif arg == '--inches': + UNITS = 'G20' + UNIT_SPEED_FORMAT = 'in/min' + UNIT_FORMAT = 'in' def export(objectslist, filename, argstring): @@ -156,6 +165,7 @@ def export(objectslist, filename, argstring): print(i.Name) global UNITS global UNIT_FORMAT + global UNIT_SPEED_FORMAT print("postprocessing...") gcode = "" @@ -169,11 +179,7 @@ def export(objectslist, filename, argstring): # Write the preamble if OUTPUT_COMMENTS: for item in objectslist: - if hasattr(item, "Proxy"): - itm_trgt = item.Proxy - else: - itm_trgt = item - if isinstance(itm_trgt, PathScripts.PathToolController.ToolController): + if hasattr(item, "Proxy") and isinstance(item.Proxy, PathScripts.PathToolController.ToolController): gcode += ";T{}={}\n".format(item.ToolNumber, item.Name) gcode += linenumber() + ";begin preamble\n" for line in PREAMBLE.splitlines(True): @@ -283,7 +289,7 @@ def parse(pathobj): if c.Name not in ["G0", "G00"]: # centroid doesn't use rapid speeds speed = Units.Quantity(c.Parameters['F'], FreeCAD.Units.Velocity) commandlist.append( - param + format(float(speed.getValueAs(UNIT_FORMAT)), feed_precision_string)) + param + format(float(speed.getValueAs(UNIT_SPEED_FORMAT)), feed_precision_string)) elif param == 'H': commandlist.append(param + str(int(c.Parameters['H']))) elif param == 'S': @@ -291,8 +297,9 @@ def parse(pathobj): elif param == 'T': commandlist.append(param + str(int(c.Parameters['T']))) else: + pos = Units.Quantity(c.Parameters[param], FreeCAD.Units.Length) commandlist.append( - param + format(c.Parameters[param], axis_precision_string)) + param + format(float(pos.getValueAs(UNIT_FORMAT)), axis_precision_string)) outstr = str(commandlist) outstr = outstr.replace('[', '') outstr = outstr.replace(']', '') @@ -328,4 +335,4 @@ def parse(pathobj): return out -# print(__name__ + " gcode postprocessor loaded.") +print(__name__ + " gcode postprocessor loaded.")