Advertisement
danfalck

find_outer_wires.py

Nov 25th, 2012
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.05 KB | None | 0 0
  1. import DraftGeomUtils
  2. import Draft
  3. from FreeCAD import Vector,Base
  4.  
  5. def findOutsideWire(wires):
  6.     samediagonal = []
  7.     if len(wires)>1:
  8.         outside = wires[0]
  9.         biggest = wires[0].BoundBox.DiagonalLength
  10.         #wires.remove(outside)
  11.         for w in wires:
  12.  
  13.             if (w.BoundBox.DiagonalLength >= biggest) and (w.Length < outside.Length) :
  14.  
  15. #                if (w.BoundBox.DiagonalLength == biggest):
  16. #                    samediagonal.append(outside)
  17. #                    samediagonal.append(w)
  18.  
  19.                 biggest = w.BoundBox.DiagonalLength
  20.                 outside = w
  21.         wires.remove(outside)
  22.         return outside, wires, samediagonal
  23.     else:
  24.         return wires
  25.  
  26. def openFilter(wires):
  27.     #filter out open wires
  28.     wirelist = []
  29.     for w in wires:
  30.         if w.isClosed():
  31.             wirelist.append(w)
  32.     return wirelist
  33.  
  34. def edgelist(obj):
  35.     #make a list of all edges in an object
  36.     edges = []
  37.     for e in obj.Shape.Edges:
  38.         edges.append(e)
  39.     return edges
  40.  
  41. def horizontal(edges):
  42.     #find all horizontal edges and discard the rest
  43.     edgelist = []
  44.     for e in edges:
  45.         if e.BoundBox.ZMin == e.BoundBox.ZMax:
  46.             edgelist.append(e)
  47.     return edgelist
  48.  
  49. def sameDiagonals(wir):
  50.     wlist = []
  51.     first = wir[0]
  52.     for w in wir:
  53.         if (w.BoundBox.DiagonalLength == first.BoundBox.DiagonalLength):
  54.             print 'pair'
  55.             wlist.append(w)
  56.         wir.remove(first)
  57.         first = wir[0]
  58.     return wlist
  59.  
  60.  
  61. sel = FreeCADGui.Selection.getSelection()[0]
  62. obj = sel
  63. el = edgelist(obj)
  64. hl = horizontal(el)
  65. connected = DraftGeomUtils.findWires(hl)
  66. goodwires = openFilter(connected)
  67.  
  68. outerwires ,innerwires, same = findOutsideWire(goodwires)
  69. #get distance from outerwires Z to bottom of part
  70. zdiff = obj.Shape.BoundBox.ZMin- outerwires.BoundBox.ZMax
  71. outerwires.Placement.move(Vector(0,0,zdiff))
  72. Part.show(outerwires)
  73.  
  74. zupperouter = outerwires
  75. zupperouter.Placement.move(Vector(0,0,obj.Shape.BoundBox.ZMax))
  76. Part.show(zupperouter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement