FreeCAD
37 строк · 1.1 Кб
1# FreeCAD TemplatePyMod module
2# (c) 2010 Werner Mayer LGPL
3
4
5import Mesh,Part,MeshPart
6
7faces = []
8mesh = App.ActiveDocument.ActiveObject.Mesh
9segments = mesh.getPlanarSegments(0.00001) # use rather strict tolerance here
10
11for i in segments:
12if len(i) > 0:
13# a segment can have inner holes
14wires = MeshPart.wireFromSegment(mesh, i)
15# we assume that the exterior boundary is that one with the biggest bounding box
16if len(wires) > 0:
17ext=None
18max_length=0
19for i in wires:
20if i.BoundBox.DiagonalLength > max_length:
21max_length = i.BoundBox.DiagonalLength
22ext = i
23
24wires.remove(ext)
25# all interior wires mark a hole and must reverse their orientation, otherwise Part.Face fails
26for i in wires:
27i.reverse()
28
29# make sure that the exterior wires comes as first in the list
30wires.insert(0, ext)
31faces.append(Part.Face(wires))
32
33
34shell=Part.Compound(faces)
35Part.show(shell)
36#solid = Part.Solid(Part.Shell(faces))
37#Part.show(solid)
38
39