Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #***************************************************************************
- #* *
- #* Copyright (c) 2013 Daniel Falck <ddfalck@gmail.com> *
- #* *
- #* This program is free software; you can redistribute it and/or modify *
- #* it under the terms of the GNU Lesser General Public License (LGPL) *
- #* as published by the Free Software Foundation; either version 2 of *
- #* the License, or (at your option) any later version. *
- #* for detail see the LICENCE text file. *
- #* *
- #* This program is distributed in the hope that it will be useful, *
- #* but WITHOUT ANY WARRANTY; without even the implied warranty of *
- #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- #* GNU Library General Public License for more details. *
- #* *
- #* You should have received a copy of the GNU Library General Public *
- #* License along with this program; if not, write to the Free Software *
- #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
- #* USA *
- #* *
- #***************************************************************************
- '''
- This macro makes a list of holes for drilling from a solid
- 1. Select a solid object that has holes in it and run the macro
- 2. It only collects info on holes that are parallel to the Z axis- I don't have a 4 or 5 axis mill at the moment
- 3. It pulls the center of the hole bounding box and the XLength for it's diameter
- 4. It will place a list of the holes on the clipboard
- 5. Uncomment the line that starts with '#Draft.makeLine' and manipulate it, if you want to see lines down the center of each hole.
- 6. Manipulate the line that starts with 'holelist.append' to make the list fit your own needs- I've put the ZMax at the ZMax of the solid's bounding box
- because I want to make sure that my drill tip doesn't collide with anything on the top of the part. YMMV.
- '''
- from PyQt4 import QtCore, QtGui, QtWebKit
- import Part
- import FreeCADGui, FreeCAD
- from math import pi
- html = """
- <HTML>
- <HEAD>
- <TITLE>Test Input</TITLE>
- <SCRIPT LANGUAGE="JavaScript">
- function testResults (form) {
- var depthVar = form.depth.value;
- var standoffVar = form.standoff.value;
- var dwellVar = form.dwell.value;
- pyObj.newBox(depthVar,standoffVar,dwellVar);
- }</SCRIPT>
- </HEAD>
- <BODY>
- <FORM NAME="myform" ACTION="" METHOD="GET">
- <table> <TR>
- <TH align=right>Drill Depth:
- <TD><INPUT TYPE="text" NAME="depth" VALUE=""><TR>
- <TH align=right>Safety Height:
- <TD><INPUT TYPE="text" NAME="standoff" VALUE=""><TR>
- <TH align=right>Dwell Time:
- <TD><INPUT TYPE="text" NAME="dwell" VALUE=""><TR> </table>
- <INPUT TYPE="button" NAME="button" Value="Get Holes" onClick="testResults(this.form)">
- </FORM> </BODY> </HTML>
- """
- depth=1
- standoff=10.0
- dwell=1
- def findholes():
- sel=Gui.Selection.getSelection()
- obj = sel[0].Shape
- facelist = []
- holelist =[]
- vz = Base.Vector(0,0,1)
- for f in obj.Faces:
- if ( round(f.ParameterRange[0], 8)==0.0 ) and ( round(f.ParameterRange[1],8) == round(pi*2, 8) ) : #eliminate flat faces
- facelist.append(f)
- for h in facelist:
- for w in h.Wires:
- for c in w.Edges:
- if ( isinstance(c.Curve,Part.Line)):
- v0=Base.Vector(c.Vertexes[0].X, c.Vertexes[0].Y, c.Vertexes[0].Z); v1=Base.Vector(c.Vertexes[1].X,c.Vertexes[1].Y, c.Vertexes[1].Z)
- if (v1.sub(v0).x == 0) and (v1.sub(v0).y == 0):
- lsp = Base.Vector(h.BoundBox.Center.x,h.BoundBox.Center.y,h.BoundBox.ZMax)
- lep = Base.Vector(h.BoundBox.Center.x,h.BoundBox.Center.y,h.BoundBox.ZMin)
- if obj.isInside(lsp, 0,False) or obj.isInside(lep, 0,False):
- pass
- else:
- Draft.makeLine((h.BoundBox.Center.x,h.BoundBox.Center.y,obj.BoundBox.ZMax ),(h.BoundBox.Center.x,h.BoundBox.Center.y,h.BoundBox.ZMin ))
- x =h.BoundBox.Center.x;y=h.BoundBox.Center.y;zmax=obj.BoundBox.ZMax;zmin=h.BoundBox.ZMin;diameter=h.BoundBox.XLength
- holelist.append((diameter, x,y,zmax,zmin))
- clipboard = QtGui.QApplication.clipboard()
- clipboard.setText(str(holelist))
- class TestClass(QtCore.QObject):
- @QtCore.pyqtSlot(str,str,str)
- def newBox(self, msg1,msg2,msg3):
- depth = (msg1);standoff = (msg2); dwell= (msg3)
- holes = findholes()
- peck_depth=0.0625
- retract_mode=0
- spindle_mode=0
- FreeCAD.Console.PrintMessage("depth ="+ str(depth)+"\n")
- FreeCAD.Console.PrintMessage("standoff = "+ str(standoff)+ "\n")
- FreeCAD.Console.PrintMessage("dwell= "+ str(dwell) + "\n")
- FreeCAD.Console.PrintMessage("peck_depth = "+ str(peck_depth) + "\n")
- FreeCAD.Console.PrintMessage("retract_mode= "+ str(retract_mode) + "\n")
- FreeCAD.Console.PrintMessage("spindle_mode="+ str(spindle_mode) + "\n")
- for h in holes:
- st = ("drill("+str(h[1][0])+ "," +str(h[1][1])+ ",depth,standoff,dwell,peck_depth,retract_mode,spindle_mode)" )
- FreeCAD.Console.PrintMessage(st+"\n")
- myObj = TestClass()
- WebGui.openBrowser('DrillOps')
- mw = FreeCADGui.getMainWindow()
- FreeCAD.Console.PrintMessage(str(mw))
- v= mw.findChild(QtWebKit.QWebFrame)
- curr1 = v.page()
- frame1 = curr1.currentFrame()
- frame1.setContent(html)
- frame1.addToJavaScriptWindowObject("pyObj", myObj)
Add Comment
Please, Sign In to add comment