| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | import FreeCAD |
| | import Part |
| | import Path |
| | import PathScripts.PathUtils as PathUtils |
| | import datetime |
| | import importDXF |
| | from builtins import open as pyopen |
| |
|
| | TOOLTIP = """ |
| | This is a postprocessor file for the Path workbench. It is used to |
| | take a pseudo-G-code fragment outputted by a Path object, and output |
| | a dxf file. |
| | Operations are output to layers. |
| | vertical moves are ignore |
| | All path moves are flattened to z=0 |
| | |
| | Does NOT remove redundant lines. If you have multiple step-downs in your |
| | operation, you'll get multiple redundant lines in your dxf. |
| | |
| | import dxf_post |
| | """ |
| |
|
| | TOOLTIP_ARGS = """ |
| | Arguments for dxf: |
| | """ |
| | now = datetime.datetime.now() |
| |
|
| | |
| | OUTPUT_HEADER = True |
| |
|
| | if False: |
| | Path.Log.setLevel(Path.Log.Level.DEBUG, Path.Log.thisModule()) |
| | Path.Log.trackModule(Path.Log.thisModule()) |
| | else: |
| | Path.Log.setLevel(Path.Log.Level.INFO, Path.Log.thisModule()) |
| | Path.Log.setLevel(Path.Log.Level.INFO, Path.Log.thisModule()) |
| |
|
| |
|
| | def processArguments(argstring): |
| | pass |
| | |
| |
|
| |
|
| | def export(objectslist, filename, argstring): |
| | doc = FreeCAD.ActiveDocument |
| | print("postprocessing...") |
| | layers = [] |
| | processArguments(argstring) |
| | for i in objectslist: |
| | result = parse(i) |
| | if len(result) > 0: |
| | layername = i.Name |
| | grp = doc.addObject("App::DocumentObjectGroup", layername) |
| | for o in result: |
| | o.adjustRelativeLinks(grp) |
| | grp.addObject(o) |
| | layers.append(grp) |
| |
|
| | dxfWrite(layers, filename) |
| |
|
| |
|
| | def dxfWrite(objlist, filename): |
| | importDXF.export(objlist, filename) |
| |
|
| |
|
| | def parse(pathobj): |
| | """accepts a Path object. Returns a list of wires""" |
| |
|
| | feedcommands = Path.Geom.CmdMove |
| | rapidcommands = Path.Geom.CmdMoveRapid |
| |
|
| | edges = [] |
| | objlist = [] |
| |
|
| | |
| | curPoint = FreeCAD.Vector(0, 0, 0) |
| | for c in PathUtils.getPathWithPlacement(pathobj).Commands: |
| | Path.Log.debug("{} -> {}".format(curPoint, c)) |
| | if "Z" in c.Parameters: |
| | newparams = c.Parameters |
| | newparams.pop("Z", None) |
| | flatcommand = Path.Command(c.Name, newparams) |
| | c.Parameters = newparams |
| | else: |
| | flatcommand = c |
| |
|
| | |
| | if flatcommand.Name not in feedcommands + rapidcommands: |
| | Path.Log.debug("non move") |
| | continue |
| |
|
| | |
| | if ( |
| | flatcommand.Parameters.get("X", curPoint.x) == curPoint.x |
| | and flatcommand.Parameters.get("Y", curPoint.y) == curPoint.y |
| | ): |
| | Path.Log.debug("vertical") |
| | continue |
| |
|
| | |
| | if flatcommand.Name in feedcommands: |
| | edges.append(Path.Geom.edgeForCmd(flatcommand, curPoint)) |
| | Path.Log.debug("feeding move") |
| |
|
| | |
| | curPoint.x = flatcommand.Parameters.get("X", curPoint.x) |
| | curPoint.y = flatcommand.Parameters.get("Y", curPoint.y) |
| |
|
| | if len(edges) > 0: |
| | candidates = Part.sortEdges(edges) |
| | for c in candidates: |
| | obj = FreeCAD.ActiveDocument.addObject("Part::Feature", "Wire") |
| | obj.Shape = Part.Wire(c) |
| | objlist.append(obj) |
| |
|
| | return objlist |
| |
|