SHOW:
|
|
- or go back to the newest paste.
| 1 | #*************************************************************************** | |
| 2 | #* * | |
| 3 | #* Copyright (c) 2013 Daniel Falck <[email protected]> * | |
| 4 | #* * | |
| 5 | #* This program is free software; you can redistribute it and/or modify * | |
| 6 | #* it under the terms of the GNU Lesser General Public License (LGPL) * | |
| 7 | #* as published by the Free Software Foundation; either version 2 of * | |
| 8 | #* the License, or (at your option) any later version. * | |
| 9 | #* for detail see the LICENCE text file. * | |
| 10 | #* * | |
| 11 | #* This program is distributed in the hope that it will be useful, * | |
| 12 | #* but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 13 | #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 14 | #* GNU Library General Public License for more details. * | |
| 15 | #* * | |
| 16 | #* You should have received a copy of the GNU Library General Public * | |
| 17 | #* License along with this program; if not, write to the Free Software * | |
| 18 | #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * | |
| 19 | #* USA * | |
| 20 | #* * | |
| 21 | #*************************************************************************** | |
| 22 | ''' | |
| 23 | This macro makes a list of holes for drilling from a solid | |
| 24 | 1. Select a solid object that has holes in it and run the macro | |
| 25 | 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 | |
| 26 | 3. It pulls the center of the hole bounding box and the XLength for it's diameter | |
| 27 | 4. It will place a list of the holes on the clipboard | |
| 28 | 5. Uncomment the line that starts with '#Draft.makeLine' and manipulate it, if you want to see lines down the center of each hole. | |
| 29 | - | html2 = """ |
| 29 | + | 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 |
| 30 | because I want to make sure that my drill tip doesn't collide with anything on the top of the part. YMMV. | |
| 31 | ''' | |
| 32 | ||
| 33 | from PyQt4 import QtCore, QtGui, QtWebKit | |
| 34 | import Part | |
| 35 | import FreeCADGui, FreeCAD | |
| 36 | from math import pi | |
| 37 | ||
| 38 | html = """ | |
| 39 | <HTML> | |
| 40 | <HEAD> | |
| 41 | <TITLE>Test Input</TITLE> | |
| 42 | <SCRIPT LANGUAGE="JavaScript"> | |
| 43 | function testResults (form) {
| |
| 44 | var depthVar = form.depth.value; | |
| 45 | var standoffVar = form.standoff.value; | |
| 46 | var dwellVar = form.dwell.value; | |
| 47 | pyObj.newBox(depthVar,standoffVar,dwellVar); | |
| 48 | }</SCRIPT> | |
| 49 | </HEAD> | |
| 50 | - | <INPUT TYPE="button" NAME="button" Value="Get Holes2" onClick="testResults(this.form)"> |
| 50 | + | |
| 51 | <FORM NAME="myform" ACTION="" METHOD="GET"> | |
| 52 | <table> <TR> | |
| 53 | <TH align=right>Drill Depth: | |
| 54 | <TD><INPUT TYPE="text" NAME="depth" VALUE=""><TR> | |
| 55 | <TH align=right>Safety Height: | |
| 56 | <TD><INPUT TYPE="text" NAME="standoff" VALUE=""><TR> | |
| 57 | <TH align=right>Dwell Time: | |
| 58 | <TD><INPUT TYPE="text" NAME="dwell" VALUE=""><TR> </table> | |
| 59 | <INPUT TYPE="button" NAME="button" Value="Get Holes" onClick="testResults(this.form)"> | |
| 60 | </FORM> </BODY> </HTML> | |
| 61 | """ | |
| 62 | ||
| 63 | depth=1 | |
| 64 | - | holelist = [] |
| 64 | + | |
| 65 | dwell=1 | |
| 66 | - | if f.ParameterRange[1]> 6.28318 and f.ParameterRange[1]< 6.283186 : #eliminate flat faces |
| 66 | + | |
| 67 | def findholes(): | |
| 68 | sel=Gui.Selection.getSelection() | |
| 69 | obj = sel[0].Shape | |
| 70 | - | curvelist=[] |
| 70 | + | |
| 71 | facelist = [] | |
| 72 | holelist =[] | |
| 73 | - | if ( isinstance(c.Curve,Part.Circle) ): |
| 73 | + | vz = Base.Vector(0,0,1) |
| 74 | - | curvelist.append((c.Curve.Radius,c.Curve.Center.x,c.Curve.Center.y)) |
| 74 | + | |
| 75 | - | coords = list(set(curvelist[:])) |
| 75 | + | if ( round(f.ParameterRange[0], 8)==0.0 ) and ( round(f.ParameterRange[1],8) == round(pi*2, 8) ) : #eliminate flat faces |
| 76 | - | holelist.append(list((coords[0][0], (coords[0][1],coords[0][2]),h.BoundBox.ZMax,h.BoundBox.ZMin))) |
| 76 | + | |
| 77 | - | return holelist |
| 77 | + | |
| 78 | - | #FreeCAD.Console.PrintMessage(str(holelist)) |
| 78 | + | |
| 79 | - | # clipboard = QtGui.QApplication.clipboard() |
| 79 | + | |
| 80 | - | # clipboard.setText(str(holelist)) |
| 80 | + | |
| 81 | if ( isinstance(c.Curve,Part.Line)): | |
| 82 | 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) | |
| 83 | if (v1.sub(v0).x == 0) and (v1.sub(v0).y == 0): | |
| 84 | lsp = Base.Vector(h.BoundBox.Center.x,h.BoundBox.Center.y,h.BoundBox.ZMax) | |
| 85 | lep = Base.Vector(h.BoundBox.Center.x,h.BoundBox.Center.y,h.BoundBox.ZMin) | |
| 86 | if obj.isInside(lsp, 0,False) or obj.isInside(lep, 0,False): | |
| 87 | pass | |
| 88 | else: | |
| 89 | Draft.makeLine((h.BoundBox.Center.x,h.BoundBox.Center.y,obj.BoundBox.ZMax ),(h.BoundBox.Center.x,h.BoundBox.Center.y,h.BoundBox.ZMin )) | |
| 90 | x =h.BoundBox.Center.x;y=h.BoundBox.Center.y;zmax=obj.BoundBox.ZMax;zmin=h.BoundBox.ZMin;diameter=h.BoundBox.XLength | |
| 91 | holelist.append((diameter, x,y,zmax,zmin)) | |
| 92 | clipboard = QtGui.QApplication.clipboard() | |
| 93 | clipboard.setText(str(holelist)) | |
| 94 | ||
| 95 | class TestClass(QtCore.QObject): | |
| 96 | @QtCore.pyqtSlot(str,str,str) | |
| 97 | def newBox(self, msg1,msg2,msg3): | |
| 98 | depth = (msg1);standoff = (msg2); dwell= (msg3) | |
| 99 | ||
| 100 | holes = findholes() | |
| 101 | peck_depth=0.0625 | |
| 102 | retract_mode=0 | |
| 103 | spindle_mode=0 | |
| 104 | FreeCAD.Console.PrintMessage("depth ="+ str(depth)+"\n")
| |
| 105 | FreeCAD.Console.PrintMessage("standoff = "+ str(standoff)+ "\n")
| |
| 106 | FreeCAD.Console.PrintMessage("dwell= "+ str(dwell) + "\n")
| |
| 107 | FreeCAD.Console.PrintMessage("peck_depth = "+ str(peck_depth) + "\n")
| |
| 108 | - | a = QtGui.qApp |
| 108 | + | |
| 109 | - | FreeCAD.Console.PrintMessage(str(a)) |
| 109 | + | |
| 110 | - | mw = a.activeWindow() |
| 110 | + | |
| 111 | for h in holes: | |
| 112 | st = ("drill("+str(h[1][0])+ "," +str(h[1][1])+ ",depth,standoff,dwell,peck_depth,retract_mode,spindle_mode)" )
| |
| 113 | FreeCAD.Console.PrintMessage(st+"\n") | |
| 114 | ||
| 115 | myObj = TestClass() | |
| 116 | ||
| 117 | WebGui.openBrowser('DrillOps')
| |
| 118 | ||
| 119 | mw = FreeCADGui.getMainWindow() | |
| 120 | FreeCAD.Console.PrintMessage(str(mw)) | |
| 121 | v= mw.findChild(QtWebKit.QWebFrame) | |
| 122 | ||
| 123 | curr1 = v.page() | |
| 124 | frame1 = curr1.currentFrame() | |
| 125 | frame1.setContent(html) | |
| 126 | frame1.addToJavaScriptWindowObject("pyObj", myObj) |