| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | import datetime |
| | import Path.Post.Utils as PostUtils |
| | import PathScripts.PathUtils as PathUtils |
| | from builtins import open as pyopen |
| |
|
| | now = datetime.datetime.now() |
| |
|
| | """ |
| | Generate g-code compatible with fablin from a Path. |
| | |
| | import fablin_post |
| | fablin_post.export(object,"/path/to/file.ncc") |
| | """ |
| |
|
| | TOOLTIP_ARGS = """ |
| | Arguments for fablin: |
| | --rapids-feedrate ... feedrate to be used for rapids (e.g. --rapids-feedrate=300) |
| | --header,--no-header ... output headers (--header) |
| | --comments,--no-comments ... output comments (--comments) |
| | --line-numbers,--no-line-numbers ... prefix with line numbers (--no-lin-numbers) |
| | --show-editor, --no-show-editor ... pop up editor before writing output(--show-editor) |
| | """ |
| |
|
| | |
| | OUTPUT_COMMENTS = False |
| | OUTPUT_HEADER = False |
| | OUTPUT_LINE_NUMBERS = False |
| | OUTPUT_TOOL_CHANGE = False |
| |
|
| | SHOW_EDITOR = True |
| | MODAL = False |
| | COMMAND_SPACE = " " |
| | LINENR = 100 |
| |
|
| | |
| | UNITS = "" |
| | MACHINE_NAME = "FABLIN" |
| | CORNER_MIN = {"x": 0, "y": 0, "z": 0} |
| | CORNER_MAX = {"x": 500, "y": 300, "z": 300} |
| |
|
| | RAPID_MOVES = ["G0", "G00"] |
| |
|
| | RAPID_FEEDRATE = 10000 |
| |
|
| | |
| | PREAMBLE = """G90 |
| | """ |
| |
|
| | |
| | POSTAMBLE = """M5 |
| | G00 X-1.0 Y1.0 |
| | G90 |
| | """ |
| |
|
| | |
| | SUPPRESS_COMMANDS = ["G98", "G80", "M6", "G17"] |
| |
|
| | |
| | PRE_OPERATION = """""" |
| |
|
| | |
| | POST_OPERATION = """""" |
| |
|
| | |
| | TOOL_CHANGE = """""" |
| |
|
| |
|
| | def processArguments(argstring): |
| | global OUTPUT_HEADER |
| | global OUTPUT_COMMENTS |
| | global OUTPUT_LINE_NUMBERS |
| | global SHOW_EDITOR |
| | global RAPID_FEEDRATE |
| | for arg in argstring.split(): |
| | if arg == "--header": |
| | OUTPUT_HEADER = True |
| | elif arg == "--no-header": |
| | OUTPUT_HEADER = False |
| | elif arg == "--comments": |
| | OUTPUT_COMMENTS = True |
| | elif arg == "--no-comments": |
| | OUTPUT_COMMENTS = False |
| | elif arg == "--line-numbers": |
| | OUTPUT_LINE_NUMBERS = True |
| | elif arg == "--no-line-numbers": |
| | OUTPUT_LINE_NUMBERS = False |
| | elif arg == "--show-editor": |
| | SHOW_EDITOR = True |
| | elif arg == "--no-show-editor": |
| | SHOW_EDITOR = False |
| |
|
| | params = arg.split("=") |
| |
|
| | if params[0] == "--rapids-feedrate": |
| | RAPID_FEEDRATE = params[1] |
| |
|
| |
|
| | def export(objectslist, filename, argstring): |
| | processArguments(argstring) |
| | global UNITS |
| | for obj in objectslist: |
| | if not hasattr(obj, "Path"): |
| | print( |
| | "the object " + obj.Name + " is not a path. Please select only path and Compounds." |
| | ) |
| | return |
| |
|
| | print("postprocessing...") |
| | gcode = "" |
| |
|
| | |
| | |
| | |
| | myMachine = None |
| | for pathobj in objectslist: |
| | if hasattr(pathobj, "Group"): |
| | for p in pathobj.Group: |
| | if p.Name == "Machine": |
| | myMachine = p |
| | if myMachine is None: |
| | print("No machine found in this project") |
| | else: |
| | if myMachine.MachineUnits == "Metric": |
| | UNITS = "G21" |
| | else: |
| | UNITS = "G20" |
| |
|
| | |
| | if OUTPUT_HEADER: |
| | gcode += linenumber() + "(Exported by FreeCAD)\n" |
| | gcode += linenumber() + "(Post Processor: " + __name__ + ")\n" |
| | gcode += linenumber() + "(Output Time:" + str(now) + ")\n" |
| |
|
| | |
| | if OUTPUT_COMMENTS: |
| | gcode += linenumber() + "(begin preamble)\n" |
| | for line in PREAMBLE.splitlines(): |
| | gcode += linenumber() + line + "\n" |
| |
|
| | for obj in objectslist: |
| |
|
| | |
| | if OUTPUT_COMMENTS: |
| | gcode += linenumber() + "(begin operation: " + obj.Label + ")\n" |
| | for line in PRE_OPERATION.splitlines(True): |
| | gcode += linenumber() + line |
| |
|
| | gcode += parse(obj) |
| |
|
| | |
| | if OUTPUT_COMMENTS: |
| | gcode += linenumber() + "(finish operation: " + obj.Label + ")\n" |
| | for line in POST_OPERATION.splitlines(True): |
| | gcode += linenumber() + line |
| |
|
| | |
| |
|
| | if OUTPUT_COMMENTS: |
| | gcode += "(begin postamble)\n" |
| | for line in POSTAMBLE.splitlines(): |
| | gcode += linenumber() + line + "\n" |
| |
|
| | if SHOW_EDITOR: |
| | dia = PostUtils.GCodeEditorDialog() |
| | dia.editor.setPlainText(gcode) |
| | result = dia.exec_() |
| | if result: |
| | final = dia.editor.toPlainText() |
| | else: |
| | final = gcode |
| | else: |
| | final = gcode |
| |
|
| | print("done postprocessing.") |
| |
|
| | if not filename == "-": |
| | gfile = pyopen(filename, "w") |
| | gfile.write(final) |
| | gfile.close() |
| |
|
| | return final |
| |
|
| |
|
| | def linenumber(): |
| | global LINENR |
| | if OUTPUT_LINE_NUMBERS is True: |
| | LINENR += 10 |
| | return "N" + str(LINENR) + " " |
| | return "" |
| |
|
| |
|
| | def parse(pathobj): |
| | out = "" |
| | lastcommand = None |
| |
|
| | params = [ |
| | "X", |
| | "Y", |
| | "Z", |
| | "A", |
| | "B", |
| | "I", |
| | "J", |
| | "F", |
| | "S", |
| | "T", |
| | "Q", |
| | "R", |
| | "L", |
| | ] |
| |
|
| | if hasattr(pathobj, "Group"): |
| | if OUTPUT_COMMENTS: |
| | out += linenumber() + "(compound: " + pathobj.Label + ")\n" |
| | for p in pathobj.Group: |
| | out += parse(p) |
| | return out |
| | else: |
| |
|
| | if not hasattr(pathobj, "Path"): |
| | return out |
| |
|
| | if OUTPUT_COMMENTS: |
| | out += linenumber() + "(Path: " + pathobj.Label + ")\n" |
| |
|
| | for c in PathUtils.getPathWithPlacement(pathobj).Commands: |
| | outstring = [] |
| | command = c.Name |
| |
|
| | |
| | if command.startswith("("): |
| | if not OUTPUT_COMMENTS: |
| | pass |
| | else: |
| | outstring.append(command) |
| |
|
| | |
| | if MODAL is True: |
| | if command == lastcommand: |
| | outstring.pop(0) |
| |
|
| | |
| | for param in params: |
| | if param in c.Parameters: |
| | if param == "F": |
| | if command not in RAPID_MOVES: |
| | outstring.append(param + format(c.Parameters["F"], ".2f")) |
| | elif param == "T": |
| | outstring.append(param + str(c.Parameters["T"])) |
| | else: |
| | outstring.append(param + format(c.Parameters[param], ".4f")) |
| |
|
| | if command in RAPID_MOVES and command != lastcommand: |
| | outstring.append("F" + format(RAPID_FEEDRATE)) |
| |
|
| | |
| | lastcommand = command |
| |
|
| | |
| | if command == "M6": |
| | if OUTPUT_COMMENTS: |
| | out += linenumber() + "(begin toolchange)\n" |
| | if not OUTPUT_TOOL_CHANGE: |
| | outstring.insert(0, ";") |
| | else: |
| | for line in TOOL_CHANGE.splitlines(True): |
| | out += linenumber() + line |
| |
|
| | if command == "message": |
| | if OUTPUT_COMMENTS is False: |
| | out = [] |
| | else: |
| | outstring.pop(0) |
| |
|
| | if command in SUPPRESS_COMMANDS: |
| | outstring = [] |
| |
|
| | |
| | if len(outstring) >= 1: |
| | if OUTPUT_LINE_NUMBERS: |
| | outstring.insert(0, (linenumber())) |
| |
|
| | |
| | for w in outstring: |
| | out += w + COMMAND_SPACE |
| | out = out.strip() + "\n" |
| |
|
| | return out |
| |
|
| |
|
| | |
| |
|