コード例 #1
0
def getShapeFromMesh(mesh):
    import Part, MeshPart
    if mesh.isSolid() and (mesh.countComponents() == 1):
        # use the best method
        faces = []
        for f in mesh.Facets:
            p = f.Points + [f.Points[0]]
            pts = []
            for pp in p:
                pts.append(FreeCAD.Vector(pp[0], pp[1], pp[2]))
            faces.append(Part.Face(Part.makePolygon(pts)))
        shell = Part.makeShell(faces)
        solid = Part.Solid(shell)
        solid = solid.removeSplitter()
        return solid

    faces = []
    segments = mesh.getPlanarSegments(
        0.001)  # use rather strict tolerance here
    for i in segments:
        if len(i) > 0:
            wires = MeshPart.wireFromSegment(mesh, i)
            if wires:
                faces.append(makeFace(wires))
    try:
        se = Part.makeShell(faces)
    except:
        return None
    else:
        try:
            solid = Part.Solid(se)
        except:
            return se
        else:
            return solid
コード例 #2
0
def getShapeFromMesh(mesh):
    import Part, MeshPart
    if mesh.isSolid() and (mesh.countComponents() == 1):
        # use the best method
        faces = []
        for f in mesh.Facets:
            p=f.Points+[f.Points[0]]
            pts = []
            for pp in p:
                pts.append(FreeCAD.Vector(pp[0],pp[1],pp[2]))
            faces.append(Part.Face(Part.makePolygon(pts)))
        shell = Part.makeShell(faces)
        solid = Part.Solid(shell)
        solid = solid.removeSplitter()
        return solid

    faces = []  
    segments = mesh.getPlanarSegments(0.001) # use rather strict tolerance here
    for i in segments:
        if len(i) > 0:
            wires = MeshPart.wireFromSegment(mesh, i)
            if wires:
                faces.append(makeFace(wires))
    try:
        se = Part.makeShell(faces)
    except:
        return None
    else:
        try:
            solid = Part.Solid(se)
        except:
            return se
        else:
            return solid
コード例 #3
0
def wiresFromFaceGroups(mesh, faceGroups):
    wires = []

    for faceGroup in faceGroups:
        wires.append(MeshPart.wireFromSegment(mesh, faceGroup.toSegment()))

    return wires
コード例 #4
0
def getShapeFromMesh(mesh,fast=True,tolerance=0.001,flat=False,cut=True):
    import Part, MeshPart, DraftGeomUtils
    if mesh.isSolid() and (mesh.countComponents() == 1) and fast:
        # use the best method
        faces = []
        for f in mesh.Facets:
            p=f.Points+[f.Points[0]]
            pts = []
            for pp in p:
                pts.append(FreeCAD.Vector(pp[0],pp[1],pp[2]))
            try:
                f = Part.Face(Part.makePolygon(pts))
            except:
                pass
            else:
                faces.append(f)
        shell = Part.makeShell(faces)
        solid = Part.Solid(shell)
        solid = solid.removeSplitter()
        return solid

    faces = []
    segments = mesh.getPlanarSegments(tolerance)
    #print len(segments)
    for i in segments:
        if len(i) > 0:
            wires = MeshPart.wireFromSegment(mesh, i)
            if wires:
                if flat:
                    nwires = []
                    for w in wires:
                        nwires.append(DraftGeomUtils.flattenWire(w))
                    wires = nwires
                try:
                    faces.append(makeFace(wires,method=int(cut)+1))
                except:
                    return None
    try:
        se = Part.makeShell(faces)
        se = se.removeSplitter()
        if flat:
            return se
    except Part.OCCError:
        try:
            cp = Part.makeCompound(faces)
        except Part.OCCError:
            return None
        else:
            return cp
    else:
        try:
            solid = Part.Solid(se)
        except Part.OCCError:
            return se
        else:
            return solid
コード例 #5
0
def convert_meshes_to_part_objects_2():
    import Part
    doc = FreeCAD.newDocument("Box_5")
    box = doc.addObject("Part::Box", "myBox")
    box.Height = 5
    box.Length = 5
    box.Width = 5
    doc.recompute()

    import Mesh
    import Part
    import MeshPart

    obj = box  # a Mesh object must be preselected
    mesh = obj.Mesh
    segments = mesh.getPlanarSegments(
        0.00001)  # use rather strict tolerance here
    faces = []

    for i in segments:
        if len(i) > 0:
            # a segment can have inner holes
            wires = MeshPart.wireFromSegment(mesh, i)
            # we assume that the exterior boundary is that one with the biggest bounding box
            if len(wires) > 0:
                ext = None
                max_length = 0
                for i in wires:
                    if i.BoundBox.DiagonalLength > max_length:
                        max_length = i.BoundBox.DiagonalLength
                        ext = i

                wires.remove(ext)
                # all interior wires mark a hole and must reverse their orientation, otherwise Part.Face fails
                for i in wires:
                    i.reverse()

                # make sure that the exterior wires comes as first in the list
                wires.insert(0, ext)
                faces.append(Part.Face(wires))

    solid = Part.Solid(Part.Shell(faces))
    Part.show(solid)

    setview()
コード例 #6
0
ファイル: ArchCommands.py プロジェクト: msocorcim/FreeCAD
def meshToShape(obj,mark=True):
    '''meshToShape(object,[mark]): turns a mesh into a shape, joining coplanar facets. If
    mark is True (default), non-solid objects will be marked in red'''

    name = obj.Name
    import Part,MeshPart
    from draftlibs import fcgeo
    if "Mesh" in obj.PropertiesList:
        faces = []	
        mesh = obj.Mesh
        plac = obj.Placement
        segments = mesh.getPlanes(0.001) # use rather strict tolerance here
        print len(segments)," segments ",segments
        for i in segments:
            print "treating",segments.index(i),i
            if len(i) > 0:
                wires = MeshPart.wireFromSegment(mesh, i)
                print "wire done"
                print wires
                if wires:
                    faces.append(makeFace(wires))
                print "done facing"
            print "faces",faces

        try:
            se = Part.makeShell(faces)
            solid = Part.Solid(se)
        except:
            pass
        else:
            if solid.isClosed():
                FreeCAD.ActiveDocument.removeObject(name)
            newobj = FreeCAD.ActiveDocument.addObject("Part::Feature",name)
            newobj.Shape = solid
            newobj.Placement = plac
            if not solid.isClosed():
                if mark:
                    newobj.ViewObject.ShapeColor = (1.0,0.0,0.0,1.0)
            return newobj
    return None
コード例 #7
0
ファイル: ArchCommands.py プロジェクト: orlik80/free-cad
def meshToShape(obj, mark=True):
    '''meshToShape(object,[mark]): turns a mesh into a shape, joining coplanar facets. If
    mark is True (default), non-solid objects will be marked in red'''

    name = obj.Name
    import Part, MeshPart, DraftGeomUtils
    if "Mesh" in obj.PropertiesList:
        faces = []
        mesh = obj.Mesh
        plac = obj.Placement
        segments = mesh.getPlanes(0.001)  # use rather strict tolerance here
        print len(segments), " segments ", segments
        for i in segments:
            print "treating", segments.index(i), i
            if len(i) > 0:
                wires = MeshPart.wireFromSegment(mesh, i)
                print "wire done"
                print wires
                if wires:
                    faces.append(makeFace(wires))
                print "done facing"
            print "faces", faces

        try:
            se = Part.makeShell(faces)
            solid = Part.Solid(se)
        except:
            pass
        else:
            if solid.isClosed():
                FreeCAD.ActiveDocument.removeObject(name)
            newobj = FreeCAD.ActiveDocument.addObject("Part::Feature", name)
            newobj.Shape = solid
            newobj.Placement = plac
            if not solid.isClosed():
                if mark:
                    newobj.ViewObject.ShapeColor = (1.0, 0.0, 0.0, 1.0)
            return newobj
    return None
コード例 #8
0
# FreeCAD TemplatePyMod module
# (c) 2010 Werner Mayer LGPL

import Mesh, Part, MeshPart

faces = []
mesh = App.ActiveDocument.ActiveObject.Mesh
segments = mesh.getPlanarSegments(0.00001)  # use rather strict tolerance here

for i in segments:
    if len(i) > 0:
        # a segment can have inner holes
        wires = MeshPart.wireFromSegment(mesh, i)
        # we assume that the exterior boundary is that one with the biggest bounding box
        if len(wires) > 0:
            ext = None
            max_length = 0
            for i in wires:
                if i.BoundBox.DiagonalLength > max_length:
                    max_length = i.BoundBox.DiagonalLength
                    ext = i

            wires.remove(ext)
            # all interior wires mark a hole and must reverse their orientation, otherwise Part.Face fails
            for i in wires:
                i.reverse()

            # make sure that the exterior wires comes as first in the lsit
            wires.insert(0, ext)
            faces.append(Part.Face(wires))
コード例 #9
0
def meshToShape(obj, mark=True):
    '''meshToShape(object,[mark]): turns a mesh into a shape, joining coplanar facets. If
    mark is True (default), non-solid objects will be marked in red'''

    name = obj.Name
    import Part, MeshPart
    from draftlibs import fcgeo
    if "Mesh" in obj.PropertiesList:
        faces = []
        mesh = obj.Mesh
        plac = obj.Placement
        segments = mesh.getPlanes(0.001)  # use rather strict tolerance here
        print len(segments), " segments ", segments
        for i in segments:
            print "treating", segments.index(i), i
            if len(i) > 0:
                wires = MeshPart.wireFromSegment(mesh, i)
                print "wire done"
                print wires
                if len(wires) > 1:
                    # a segment can have inner holes
                    print "inner wires found"
                    ext = None
                    max_length = 0
                    # cleaning up rubbish in wires
                    for i in range(len(wires)):
                        wires[i] = fcgeo.removeInterVertices(wires[i])
                    for w in wires:
                        # we assume that the exterior boundary is that one with
                        # the biggest bounding box
                        if w.BoundBox.DiagonalLength > max_length:
                            max_length = w.BoundBox.DiagonalLength
                            ext = w
                    print "exterior wire", ext
                    wires.remove(ext)
                    # all interior wires mark a hole and must reverse
                    # their orientation, otherwise Part.Face fails
                    for w in wires:
                        print "reversing", w
                        #w.reverse()
                        print "reversed"
                    # make sure that the exterior wires comes as first in the list
                    wires.insert(0, ext)
                    print "done sorting", wires
                if wires:
                    faces.append(Part.Face(wires))
                print "done facing"
            print "faces", faces

        try:
            se = Part.makeShell(faces)
            solid = Part.Solid(se)
        except:
            pass
        else:
            if solid.isClosed():
                FreeCAD.ActiveDocument.removeObject(name)
            newobj = FreeCAD.ActiveDocument.addObject("Part::Feature", name)
            newobj.Shape = solid
            newobj.Placement = plac
            if not solid.isClosed():
                if mark:
                    newobj.ViewObject.ShapeColor = (1.0, 0.0, 0.0, 1.0)
            return newobj
    return None
コード例 #10
0
ファイル: Mesh2Shape.py プロジェクト: AjinkyaDahale/FreeCAD
# FreeCAD TemplatePyMod module  
# (c) 2010 Werner Mayer LGPL


import Mesh,Part,MeshPart

faces = []
mesh = App.ActiveDocument.ActiveObject.Mesh
segments = mesh.getPlanarSegments(0.00001) # use rather strict tolerance here

for i in segments:
   if len(i) > 0:
      # a segment can have inner holes
      wires = MeshPart.wireFromSegment(mesh, i)
      # we assume that the exterior boundary is that one with the biggest bounding box
      if len(wires) > 0:
         ext=None
         max_length=0
         for i in wires:
            if i.BoundBox.DiagonalLength > max_length:
               max_length = i.BoundBox.DiagonalLength
               ext = i

         wires.remove(ext)
         # all interior wires mark a hole and must reverse their orientation, otherwise Part.Face fails
         for i in wires:
            i.reverse()

         # make sure that the exterior wires comes as first in the list
         wires.insert(0, ext)
         faces.append(Part.Face(wires))