Code: Select all
from PySide import QtCore, QtGui
import Path
mainobj = App.ActiveDocument.ActiveObject.Shape.Edges
#create a simple input dialog box to get zdepth
zd, okPressed = QtGui.QInputDialog.getText(None, 'Z Cut Depth', '.1')
#create a simple input dialog box to get cuts per pass or step down amount
stepdown, okPressed = QtGui.QInputDialog.getText(None, 'Cut Depth per pass', 'Step down amount .015')
#create a simple input dialog box to get the tool diameter
td, okPressed = QtGui.QInputDialog.getText(None, 'Tool Diameter', '.375')
#create a simple input dialog box asking if tool comp is to the right or left side of the line
comp, okPressed = QtGui.QInputDialog.getText(None, 'Tool to left or right of line', 'Enter Left or Right')
#create a simple input dialog box to get the direction the tool is to travel like climp or conventional milling
dir, okPressed = QtGui.QInputDialog.getText(None, 'Tool traveling in a clockwise or counter clockwise direction', 'Enter CW or CCW')
#get the selected object
selobj = Gui.Selection.getSelectionEx()[0]
#subn is a tuple
subn = selobj.SubElementNames
#subnstr is subn turned from a tuple to a string
subnstr = ''.join(subn)
#strip out Edge from sour subnstr varialbe
#turn it into a number and minus 1 from it to get its location
#in the mainobj list
indexnum =int(subnstr[4:10]) -1
#mainobj is a list and indexnum is the Edge we selected
selEdge = mainobj[indexnum]
p1 = selEdge.Vertexes[0]
p2 = selEdge.Vertexes[1]
toolcomp = float(td) / 2
if dir == "ccw":
startx = p1.X
#starty = p1.Y
endx = p2.X
#endy = p2.Y
if comp == "left":
starty = p1.Y - toolcomp
endy = p2.Y - toolcomp
elif comp == "right":
starty = p1.Y + toolcomp
endy = p2.Y + toolcomp
elif dir =="cw":
startx = p2.X
#starty = p2.Y
endx = p1.X
#endy = p1.Y
if comp == "right":
starty = p2.Y - toolcomp
endy = p1.Y - toolcomp
elif comp == "left":
starty = p2.Y + toolcomp
endy = p1.Y + toolcomp
#Create path
o = App.ActiveDocument.addObject("Path::Feature","myPath")
#set p to the hold myPaths Path
#Create GCode Header
p = Path.Command("G0 X{0:.3f} Y{1:.3f} \n".format(startx,starty))
o.Path.addCommands(p)
p = Path.Command("G0 Z.1")
o.Path.addCommands(p)
zdepth = float(zd)
stpdwn = float(stepdown)
numofpass, lastpass = divmod(zdepth,stpdwn)
numofpass = int(numofpass)
#loop for step down process
for i in range(numofpass):
curzdepth = (1+i) * stpdwn
#p is our z current cut depth
p = Path.Command("G0 Z-{0:.3f} \n".format(curzdepth))
#add p to our path object
o.Path.addCommands(p)
#move to our x,y end point
p = Path.Command("G01 X{0:.3f} Y{1:.3f} \n".format(endx,endy))
#add the first path command to our new path object
o.Path .addCommands(p)
# retract in the z
p = Path.Command("G0 Z.1")
o.Path .addCommands(p)
#return to strat of path
p = Path.Command("G0 X{0:.3f} Y{1:.3f} \n".format(startx,starty))
o.Path .addCommands(p)
p = Path.Command("G0 Z-{0:.3f} \n".format(zdepth))
o.Path .addCommands(p)
p = Path.Command("G01 X{0:.3f} Y{1:.3f} F20.\n".format(endx,endy))
o.Path .addCommands(p)
p = Path.Command("G0 Z.1 \n")
o.Path .addCommands(p)
Code: Select all
#mainobj = App.ActiveDocument.ActiveObject.Shape.Edges
mainobj = App.ActiveDocument.Sketch.Shape.Edges
If i run this code in the python console it always points to 'myPath' no matter what object is actively selected.
Code: Select all
mainobj = App.ActiveDocument.ActiveObject.Name
print(mainobj)
OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.18946 (Git)
Build type: Release
Branch: master
Hash: 0175008ceba01666449657086ca036fc59e0e6c7
Python version: 3.7.3
Qt version: 5.12.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United States (en_US)