Rhino3dm extrusion to brep

Hi all,

I am using this method to convert an extrusion into a brep as I am interested in accessing individual faces.

In the image below, on the left-hand side you have extrusion and on the right-hand side the same extrusion is converted into closed polysurface in rhino through convertExtrusion command.

I am using rhino3dm python. When I access the faces of the closed polysurface I get six faces which I expect. However, when I try accessing the faces of a brep created from extrusion using the ToBrep method then I am only able to access two faces. Why does this happen? What am I missing here?

On an additional note, when I check the length of faces in the brep created from extrusion in rhino3dm through ToBrep method, it shows as 6, which is right.

Following is how I am doing this to be explicit.

print(len(brep.Faces)) # length check
for i in range(len(brep.Faces)): # Trying to print all faces 
      print(brep.Faces[i])

Thanks!
extrusion to brep

Hi @Devang_Chauhan,

This code works with this file using Python 3.7:

import rhino3dm

model = rhino3dm.File3dm.Read('/Users/Dale/Downloads/extrusion_box.3dm')
geometry = model.Objects[0].Geometry
if isinstance(geometry, rhino3dm.Extrusion):
    brep = geometry.ToBrep(True)
    if brep:
        print(len(brep.Faces))

extrusion_box.3dm (28.1 KB)

What am I missing?

Thanks,

– Dale

@Dale, the problem is accessing all the faces. For instance, if you do

        for face in brep.Faces:
            print(face)

You get only two prints instead of four. Same if you try to access with a running index idx from 0-5 over brep.Faces[idx].

Output of your script modified to

import rhino3dm

model = rhino3dm.File3dm.Read(r'C:\Users\Nathan\Downloads\extrusion_box.3dm')
geometry = model.Objects[0].Geometry
if isinstance(geometry, rhino3dm.Extrusion):
    brep = geometry.ToBrep(True)
    if brep:
        print(len(brep.Faces))
        for i in range(0, len(brep.Faces)):
            print(brep.Faces[i])

is

6
<rhino3dm._rhino3dm.BrepFace object at 0x000001BF7B80FED8>
<rhino3dm._rhino3dm.BrepFace object at 0x000001BF7B8B9068>

Thanks a lot @nathanletwory for demonstrating the problem.

@dale, as you can see in the output, the length of faces is 6 which is right. But only 2 faces are being printed. That is the problem.

Thanks for the clarification. I’ve logged the issue.

https://mcneel.myjetbrains.com/youtrack/issue/RH3DM-128

– Dale

Hi @stevebaer,

Thanks for the new release today.

I tried the new release and observed the following behavior. The rhino file has a box test.3dm (40.9 KB) which comes as an Extrusion object in rhino3dm.

import rhino3dm

path = r"C:\Users\devan\Desktop\test.3dm"
file_3dm = rhino3dm.File3dm.Read(path)

for obj in file_3dm.Objects:
    geo = obj.Geometry

    #Converting extrusion to brep and then each brep face into mesh
    if isinstance(geo, rhino3dm.Extrusion):
        brep = geo.ToBrep(True)
        for i in range(len(brep.Faces)):
            face = brep.Faces[i].DuplicateFace(True)
            mesh = face.Faces[0].GetMesh(rhino3dm.MeshType.Any)
            print(mesh)

# Converting extrusion to mesh
mesh = geo.GetMesh(rhino3dm.MeshType.Any)
for i in range(len(mesh.Faces)):
    print(mesh.Faces[i])

Output

None
None
None
None
None
None
(0, 2, 3, 1)
(4, 6, 7, 5)
(8, 10, 11, 9)
(12, 14, 15, 13)
(17, 16, 19, 19)
(19, 18, 17, 17)
(21, 23, 20, 20)
(23, 21, 22, 22)

Why do I get None when I try to create a mesh from a brepFace that comes from a brep created from an extrusion? You might ask why am I doing this when I can directly convert the Extrusion object in a mesh. The reason is I want to access vertices for each face and that is only exposed for a mesh object.

Hi @Devang_Chauhan,

Rhino3dm will not create meshes from Breps. This is a limitation of openNURBS, which Rhino3dm is based on. So its always best to save 3dm files that have meshes already cached on Breps. You can easily this by just shading a viewport before saving the 3dm file.

That said, light extrusions can have cached render meshes too. So instead of converting the extrusion to a Brep and then looking for a meshes, just try looking for meshes on the extrusion.

Hope this helps.

– Dale

Thanks for your response @dale.

I made sure that the rhino file was saved in the shaded mode before I ran the script. I have been aware of that limitation for a long time now. Having said that, do you still think that those None values are valid?

Hi @Devang_Chauhan,

Yes I do, as this line:

brep = geo.ToBrep(True)

is going to create a new Brep, and that Brep is not going to have any cached meshes.

– Dale

Now that explains it. Thank you very much @dale!