Last active
May 20, 2023 17:58
-
-
Save cam72cam/6a3dd4e5c3e5cccc3c31203b1567746f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def invertPath(path): | |
CmdMoveRapid = ["G0", "G00"] | |
CmdMoveStraight = ["G1", "G01"] | |
CmdMoveCW = ["G2", "G02"] | |
CmdMoveCCW = ["G3", "G03"] | |
CmdDrill = ["G73", "G81", "G82", "G83"] | |
CmdMoveArc = CmdMoveCW + CmdMoveCCW | |
CmdMove = CmdMoveStraight + CmdMoveArc | |
commands = [] | |
for cmd in path.Commands: | |
if ( | |
(cmd.Name in CmdMoveRapid) | |
or (cmd.Name in CmdMove) | |
or (cmd.Name in CmdDrill) | |
): | |
params = cmd.Parameters | |
if "X" in params: | |
params.update({"X": - params.get("X")}); | |
# Arcs need to have the I and J params rotated as well | |
if cmd.Name in CmdMoveArc: | |
cmd.Name = "G3" if cmd.Name in CmdMoveCW else "G2" | |
if "I" in params: | |
params.update({"I": -params.get("I")}); | |
cmd.Parameters = params | |
commands.append(cmd) | |
newPath = Path.Path(commands) | |
return newPath | |
for selected in Gui.Selection.getSelection(): | |
selected.Gcode = [cm.toGCode() for cm in invertPath(selected.Path).Commands] | |
selected.Placement = FreeCAD.Placement() | |
selected.recompute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment