Code: Select all
#***************************************************************************
#*
#* 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
#*
#***************************************************************************
from FreeCAD import Part
from PyQt4 import QtGui,QtCore
'''
this macro makes a list of holes for drilling from a solid
select the solid and run the macro
it will place on the clipboard a list of holes like such:
[[5.0, (80.0, -20.0), 0.0, -5.0], [2.5, (20.0, -20.0), 0.0, -5.0])
the first element of the first item is the radius of the hole, the second it's XY coords
the third is the ZMax of the hole, the fourth ZMin
manipulate the line that starts with 'holelist.append' to make the list fit your own needs
'''
def findholes(obj):
facelist = []
holelist = []
for f in obj.Faces:
if f.ParameterRange[1]> 6.28318 and f.ParameterRange[1]< 6.283186 : #eliminate flat faces
facelist.append(f)
for h in facelist:
curvelist=[]
for w in h.Wires:
for c in w.Edges:
if ( isinstance(c.Curve,Part.Circle) ):
curvelist.append((c.Curve.Radius,c.Curve.Center.x,c.Curve.Center.y))
coords = list(set(curvelist[:]))
holelist.append(list((coords[0][0], (coords[0][1],coords[0][2]),h.BoundBox.ZMax,h.BoundBox.ZMin)))
clipboard = QtGui.QApplication.clipboard()
clipboard.setText(str(holelist))
sel=Gui.Selection.getSelection()
obj = sel[0].Shape
findholes(obj)