Iterating through Mesh.Faces list in rhino3dm python

Iterating through the MeshFaceList of a mesh in rhino3dm python (0.14.0) results in a very long strange iteration, in spite of the face count being correct. Here’s the code to replicate:

import rhino3dm as r

U = 5
V = 5

#creating a simple mesh from a grid of points
grid = []
mesh = r.Mesh()
for i in range(U):
    for j in range(V):
        p = r.Point3d(i,j,0)
        grid.append(p)
        mesh.Vertices.Add(p.X, p.Y, p.Z) 
        
for i in range(len(grid)-(V)):
    if ( i % V != V -1 ):
        mesh.Faces.AddFace(i,i+1, i+V+1,i+V)

print(mesh.Faces.Count)

for f in mesh.Faces:
    print(f)

Any idea why this might be happening?

Here’s an image of (part of) the odd result:

@stevebaer @will can you guys replicate this?

I haven’t tried yet. I have this post bookmarked and will try to repeat when I get a chance.

1 Like

Definitely funky. If you need a (slightly less pythonic) workaround then try…

for i in range(mesh.Faces.Count):
    print(mesh.Faces[i])
1 Like

thanks @will. That works for now :ok_hand: