Mesh2Shape.py

Go to the documentation of this file.
00001 # FreeCAD TemplatePyMod module  
00002 # (c) 2010 Werner Mayer LGPL
00003 
00004 
00005 import Mesh,Part,MeshPart
00006 
00007 faces = []
00008 mesh = App.ActiveDocument.ActiveObject.Mesh
00009 segments = mesh.getPlanes(0.00001) # use rather strict tolerance here
00010 
00011 for i in segments:
00012    if len(i) > 0:
00013       # a segment can have inner holes
00014       wires = MeshPart.wireFromSegment(mesh, i)
00015       # we assume that the exterior boundary is that one with the biggest bounding box
00016       if len(wires) > 0:
00017          ext=None
00018          max_length=0
00019          for i in wires:
00020             if i.BoundBox.DiagonalLength > max_length:
00021                max_length = i.BoundBox.DiagonalLength
00022                ext = i
00023 
00024          wires.remove(ext)
00025          # all interior wires mark a hole and must reverse their orientation, otherwise Part.Face fails
00026          for i in wires:
00027             i.reverse()
00028 
00029          # make sure that the exterior wires comes as first in the lsit
00030          wires.insert(0, ext)
00031          faces.append(Part.Face(wires))
00032 
00033 
00034 shell=Part.Compound(faces)
00035 Part.show(shell)
00036 #solid = Part.Solid(Part.Shell(faces))
00037 #Part.show(solid)
00038 

Generated on Wed Nov 23 19:00:22 2011 for FreeCAD by  doxygen 1.6.1