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
@Dale, the problem is accessing all the faces. For instance, if you do
for face in brep.Faces:
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
model = rhino3dm.File3dm.Read(r'C:\Users\Nathan\Downloads\extrusion_box.3dm')
geometry = model.Objects.Geometry
if isinstance(geometry, rhino3dm.Extrusion):
brep = geometry.ToBrep(True)
for i in range(0, len(brep.Faces)):
<rhino3dm._rhino3dm.BrepFace object at 0x000001BF7B80FED8>
<rhino3dm._rhino3dm.BrepFace object at 0x000001BF7B8B9068>
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.
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.GetMesh(rhino3dm.MeshType.Any)
# Converting extrusion to mesh
mesh = geo.GetMesh(rhino3dm.MeshType.Any)
for i in range(len(mesh.Faces)):
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.
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.
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?