Here is how I created the FeatureAreas into tool paths. It is similar to using the fromShape located in the supplimental commands menu under Path.
Code: Select all
import Path
# Change FeatureArea003 to the name of your FeatureArea, Sketch, Shape, or Wire
p = App.ActiveDocument.FeatureArea003
o = FreeCAD.ActiveDocument.addObject("Path::Feature","myPath")
#setting up our start vector from a choosen vertex
ov = p.Shape.Vertexes[0] #minus 1 from whatever the lower left Preselect info says
pos = ov.Point
o.Path = Path.fromShapes(p.Shape,start=pos,preamble = "false")
Code: Select all
#change for your needs
file = "/home/yourusername/.FreeCAD/Macro/FeatureAreaTut/Path.nc"
gcode =App.ActiveDocument.myPath.Path.toGCode()
with open(file, 'w+') as f:
f.write(gcode)
f.close()
Code: Select all
#cut and paste gcode and create a Path::Feature object
import Path
lines = """
paste your Edited GCode here
"""
p = Path.Path()
p.setFromGCode(lines)
o = App.ActiveDocument.addObject("Path::Feature", "myPath") #rename mypath as you see fit
o.Path = p
Code: Select all
from PySide import QtCore, QtGui
#create a simple input dialog box to get zdepth
zd, okPressed = QtGui.QInputDialog.getText(None, 'Z Cut Depth', '9.525')
#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 .635')
#create a new Path obj
o = FreeCAD.ActiveDocument.addObject("Path::Feature","myPath")
#variable setup for z step down for loop
zdepth = float(zd)
stpdwn = float(stepdown)
numofpass, lastpass = divmod(zdepth,stpdwn)
numofpass = int(numofpass)
#set p3 to the Path already created with wiretopath macro the first macro in this forum post
p3 = App.ActiveDocument.myPath003.Path #change mypath1 to your paths name
#loop for step down process
for i in range(numofpass):
curzdepth = (1+i) * stpdwn
#move to our x,y start point
p = Path.Command(" X232.318841 Y6.350000") #change this to your starting x and y location
# add the first path command to our new path object
o.Path .addCommands( p)
#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)
#add our tool path p3 which is the path pattern we want repeated to our new path object
o.Path.addCommands(p3.Commands)
#last at total zdepth
#move to x,y start point
p = Path.Command(" X232.318841 Y6.350000") #change this to your starting x and y location
o.Path .addCommands( p)
p = Path.Command("G0 Z-{0:.3f} \n".format(zdepth))
o.Path.addCommands(p)
o.Path.addCommands(p3.Commands)
#add it to the job
# PathScripts.PathUtils.addToJob(App.ActiveDocument.myPath)
# add a tool controller property to the path
# App.ActiveDocument.myPath.addProperty("App::PropertyLink", "ToolController")
Files to follow along with video link from the top.