Convert planar mesh to Brep

Hi,

Is it somehow possible to create a Brep surface from a planar mesh including several holes/openings?
I am using the python rhino3dm package (version 7.14.1) and started to create a mesh and convert it with rhino3dm.Brep.CreateFromMesh() into a brep. This resulting brep has still the mesh faces structure.

As the mesh is planar, I would like to eliminate the interior edges in the brep to get only the outside boundary and holes. Is there a function for this or is there even a manual way? Maybe my approach to get a brep with holes through a mesh is also wrong…

Here is a small example:

import rhino3dm

# init model
model = rhino3dm.File3dm()

# create and add layer
layer = rhino3dm.Layer()
layer.Color = (255, 255, 0, 255)
layer.Name = 'example'
model.Layers.Add(layer)

# create mesh
mesh = rhino3dm.Mesh()

# create list of points
points = [[0, 0, 0], [1, 1, 0], [2, 1, 0], [3, 0, 0], [3, 3, 0], [2, 2, 0], [1, 2, 0], [0, 3, 0]]
for p in points:
    mesh.Vertices.Add(p[0], p[1], p[2])

# add faces from point list
mesh.Faces.AddFace(0, 1, 6, 7)
mesh.Faces.AddFace(6, 5, 4, 7)
mesh.Faces.AddFace(2, 3, 4, 5)
mesh.Faces.AddFace(0, 3, 2, 1)

# create brep
brp = rhino3dm.Brep.CreateFromMesh(mesh, True)

# add brep to model
model.Objects.AddBrep(brp)

# save to file
model.Write('example.3dm')

Thanks in advance for your support,
Jay

Hi @Jay_Tea, try below using _EditPythonScript:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    
    mesh = Rhino.Geometry.Mesh()
    
    points = [[0, 0, 0], [1, 1, 0], [2, 1, 0], [3, 0, 0], [3, 3, 0], [2, 2, 0], [1, 2, 0], [0, 3, 0]]
    for p in points: mesh.Vertices.Add(p[0], p[1], p[2])
    
    mesh.Faces.AddFace(0, 1, 6, 7)
    mesh.Faces.AddFace(6, 5, 4, 7)
    mesh.Faces.AddFace(2, 3, 4, 5)
    mesh.Faces.AddFace(0, 3, 2, 1)
    
    mesh.FaceNormals.ComputeFaceNormals()
    mesh.Compact()
    
    polylines = mesh.GetNakedEdges()
    if not polylines: return
    
    curves = [polyline.ToNurbsCurve() for polyline in polylines]
    breps = Rhino.Geometry.Brep.CreatePlanarBreps(curves, 0.001)
    for b in breps: scriptcontext.doc.Objects.AddBrep(b)
    
    scriptcontext.doc.Views.Redraw()
    
DoSomething()

_
c.

1 Like

I think he is looking for usage of rhino3dm library, which lacks plenty of RhinoCommon methods.

Brep.CreatePlanarBreps alternative for rhino3dm library is Brep.CreateTrimmedPlane.

brp2 = rhino3dm.Brep.CreateTrimmedPlane(rhino3dm.Plane.WorldXY, outerInnerCrv_L)

To obtain the outerInnerCrv_L, you can:

  • without creating the mesh, directly create the curves from your mesh vertex coordinates.
  • in rhino3dm NET, you can get them from Brep.DuplicateNakedEdgeCurves which does not seem to exist in python version.
1 Like

Yes, you’re right. I don’t know anything about rhino3dm and asumed that the workflow might be the same as in RhinoCommon…

_
c.

1 Like