Use the face index of a mesh

Hello,

Is there any way in rhino python to select a mesh, create a dictionary of the mesh face indices as the key, and then create values corresponding to the normals of that mesh face index? If the mesh faces have indices, can you reference the data, like the normals, of those triangles?

I have been using the explode mesh command, but then that makes each triangle an individual mesh, and that eats into data and processing time.

Thanks!
Tim

Yes, but I don’t get why you’d want to do that, because the information is already there in the mesh object, that is if the normals have been calculated beforehand.

Can you expand a little on what it is that you want to do? The big picture?

Sure thing!

I would like to go through triangle by triangle and change the color of the triangle based on the angle with respect to the XY plane. I need the normals in order to calculate the angle.

Any help is appreciated!

Tim

You can iterate over mesh faces using Mesh.Faces Property. You can iterate over face normals using Mesh.FaceNormals Property.

Thank you for that response! Can you provide an example of what the code would look like if you imported a mesh and wanted to print out each normal?

Tim

With Python it would be something like:

me = GetYourMesh() # method to implemented by yourself

# ensure normals exist
me.RebuildNormals()
# loop over normals
for fn in me.FaceNormals:
    print(fn) # fn is now a Vector3f

in C# it would be something like

Rhino.Geometry.Mesh mesh = GetYourMesh(); // implement method yourself

// ensure normals exist
mesh.RebuildNormals();

// loop over normals
foreach(Rhino.Geometry.Vector3f fn in mesh.FaceNormals)
{
    // do something with the fn
}