Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import FreeCAD
- import FreeCAD as App
- import FreeCADGui as Gui
- import Part
- import Mesh
- import MeshPart
- import ocl
- #select an object in FreeCAD gui
- sel = Gui.Selection.getSelection()[0]
- #get type of object
- if sel.TypeId.startswith('Mesh'):
- #it is a mesh already
- print 'was already mesh'
- mesh = sel
- elif sel.TypeId.startswith('Part') and \
- (sel.Shape.BoundBox.XLength > 0) and \
- (sel.Shape.BoundBox.YLength > 0) and \
- (sel.Shape.BoundBox.ZLength > 0):
- print 'this is a solid Part object'
- mesh = MeshPart.meshFromShape(sel.Shape,MaxLength=2)
- else:
- print 'we cannot work with this object'
- s= ocl.STLSurf()
- for f in mesh.Facets:
- p = f.Points[0];q=f.Points[1];r=f.Points[2]
- t= ocl.Triangle(ocl.Point(p[0],p[1],p[2]),ocl.Point(q[0],q[1],q[2]),ocl.Point(r[0],r[1],r[2]))
- s.addTriangle(t)
- # define a cutter
- cutter = ocl.CylCutter(0.6, 5)
- print "creating PathDropCutter()"
- pdc = ocl.PathDropCutter() # create a pdc
- print "set STL surface"
- pdc.setSTL(s)
- print "set cutter"
- pdc.setCutter(cutter) # set the cutter
- print "set minimumZ"
- pdc.minimumZ = -1 # set the minimum Z-coordinate, or "floor" for drop-cutter
- print "set the sampling interval"
- pdc.setSampling(0.0123)
- # some parameters for this "zigzig" pattern
- xmin=sel.Shape.BoundBox.XMin - cutter.getDiameter()
- xmax=sel.Shape.BoundBox.XMax + cutter.getDiameter()
- ymin=sel.Shape.BoundBox.YMin - cutter.getDiameter()
- ymax=sel.Shape.BoundBox.YMax + cutter.getDiameter()
- zmax=sel.Shape.BoundBox.ZMax + cutter.getDiameter()
- Ny=int(sel.Shape.BoundBox.YLength/cutter.getDiameter()) # number of lines in the y-direction
- dy = float(ymax-ymin)/Ny # the y step-over
- path = ocl.Path() # create an empty path object
- # add Line objects to the path in this loop
- for n in xrange(0,Ny):
- y = ymin+n*dy
- p1 = ocl.Point(xmin,y,0) # start-point of line
- p2 = ocl.Point(xmax,y,0) # end-point of line
- l = ocl.Line(p1,p2) # line-object
- path.append( l ) # add the line to the path
- print " set the path for pdf "
- pdc.setPath( path )
- print " run the calculation "
- t_before = time.time()
- pdc.run() # run drop-cutter on the path
- t_after = time.time()
- print "run took ", t_after-t_before," s"
- print "get the results "
- clp = pdc.getCLPoints() # get
- edge = Part.Edge
- stpt = (clp[0].x, clp[0].y, clp[0].z)
- edgelist= []
- for c in clp[1:]:
- endpt = (c.x, c.y, c.z)
- edge = Part.makeLine(stpt,endpt)
- edgelist.append(edge)
- stpt = (c.x, c.y, c.z)
- comp = Part.Compound(edgelist)
- Part.show(comp)
Add Comment
Please, Sign In to add comment