Advertisement
danfalck

freecad_selection.py

Nov 11th, 2012
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.83 KB | None | 0 0
  1. import FreeCAD,FreeCADGui,Part
  2.  
  3. sel = FreeCADGui.Selection.getSelection()
  4.  
  5. for o in sel:
  6.     obj = o.Shape
  7.  
  8. #find highest bounding boxes
  9.  
  10. zmax = 0.0
  11.  
  12. for w in obj.Wires:
  13.     if w.BoundBox.ZMax >= zmax:
  14.         zmax = w.BoundBox.ZMax
  15.  
  16. print "Zmax = " + str(zmax)
  17.  
  18. #make list of highest wires
  19. topwires = []
  20.  
  21. for w in obj.Wires:
  22.     if (w.BoundBox.ZMax == zmax) and (w.BoundBox.ZMin == zmax):
  23.         topwires.append(w)
  24.  
  25. print len(topwires)
  26.  
  27. #find largest wire -most likely on outside
  28.  
  29. outside = topwires[0]
  30. biggest = topwires[0].BoundBox.DiagonalLength
  31. inside = []
  32. for t in topwires:
  33.     if t.BoundBox.DiagonalLength >= biggest:
  34.         biggest = t.BoundBox.DiagonalLength
  35.         outside = t
  36.     else:
  37.         inside.append(t)
  38.  
  39. print outside.BoundBox.DiagonalLength
  40.  
  41. for i in inside:
  42.     print i.BoundBox.DiagonalLength
  43.  
  44. ######################################################
  45.  
  46. sel = FreeCADGui.Selection.getSelection()
  47.  
  48. for o in sel:
  49.     obj = o.Shape
  50.  
  51. Ztop = obj.BoundBox.ZMax
  52. Zbottom = obj.BoundBox.ZMin
  53.  
  54. wires = obj.Wires
  55. outside = wires[0]
  56. biggest = wires[0].BoundBox.DiagonalLength
  57. inside = []
  58. for w in wires:
  59.     #acquire largest profile
  60.     if w.BoundBox.DiagonalLength >= biggest:
  61.         biggest = w.BoundBox.DiagonalLength
  62.         outside = w
  63.     #make list of inside profiles that are not lines going straight up and down
  64.     else:
  65.         if  (w.BoundBox.ZMin <> Zbottom):
  66.             if (w.BoundBox.ZMax <> w.BoundBox.ZMin) :
  67.                 pass
  68.  
  69.             else:  
  70.                 inside.append(w)
  71.  
  72.  
  73. print outside.BoundBox.DiagonalLength
  74.  
  75. for d in inside:
  76.     print d.BoundBox.DiagonalLength
  77.    
  78.  
  79. sel = FreeCADGui.Selection.getSelection()
  80.  
  81. for o in sel:
  82.     obj = o.Shape
  83.  
  84.  
  85. #find faces that are on outside profile with fillets
  86. faces = obj.Faces
  87. outerwires = []
  88. facelist = []
  89. for f in faces:
  90.     if f.BoundBox.ZLength >= .0001:
  91.         print "ZMax: "+str(f.BoundBox.ZMax)+" ZMin: "+str(f.BoundBox.ZMin)+" ZLen: "+str(f.BoundBox.ZLength)
  92.         facelist.append(f)
  93.  
  94. print len(obj.Faces)
  95. print len(facelist)
  96.  
  97. Ztop = obj.BoundBox.ZMax
  98.  
  99. wirelist = []
  100. for f in facelist:
  101.     print f.BoundBox
  102.  
  103. import Part
  104. from FreeCAD import Base, Vector
  105. import FreeCAD,FreeCADGui,Part
  106.  
  107. sel = FreeCADGui.Selection.getSelection()
  108.  
  109. for o in sel:
  110.     obj = o.Shape
  111.  
  112. Zlevel = (obj.BoundBox.ZMax-obj.BoundBox.ZMin)/2.0
  113.  
  114. wires = obj.slice(Base.Vector(0,0,1),Zlevel)
  115. comp=Part.Compound(wires)
  116. slice=FreeCAD.getDocument("freecad_blob_for_cnc").addObject("Part::Feature","Milled Edges")
  117. slice.Shape=comp
  118.  
  119.  
  120.    
  121. outside = slice.Shape.Wires[0]
  122. biggest = slice.Shape.Wires[0].BoundBox.DiagonalLength
  123. inside = []
  124. for t in slice.Shape.Wires:
  125.     if t.BoundBox.DiagonalLength >= biggest:
  126.         biggest = t.BoundBox.DiagonalLength
  127.         outside = t
  128.     else:
  129.         inside.append(t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement