How to delete a mesh face in Python script

I have a mesh with 2.2M vertices. I draw a closed curve around a region of interest and collect the curve points and the mesh vertices inside the curve in order to construct a patch mesh. If the curve has concave sides, Rhino adds mesh faces to prevent the patch from having concave sides. I need to remove these in order to get the 3D area of the patch over the closed curve. The way I do this now is to compute the centroid of each mesh face (typically 330K in the region of interest) and test if the centroid is inside the closed curve. I keep the faces found to be inside the curve and construct a new mesh. This takes some time. A faster way would be to just delete the unwanted mesh faces if this could be done inside the Python script. I have not found a Rhinoscriptsyntax command or Rhino Common command that will do this. It can be done with
rs.Command(‘NoEcho -DeleteMeshFaces {},{} Enter’.format(ptc.X,ptc.Y))
where ptc is a face centroid but after it finishes the mesh looks unchanged. If I manually execute the command everything works.

What I really want is a rs.DeleteMeshFace or Rhino Common Mesh.DeleteMeshFace method to get this job done as working with rs.Command is always hazardous (needs to be the right viewport, the viewport needs to already exist, etc.).

Any ideas?


This is probably what you’re after:

You access the method on the mesh i.e nameOfMesh.Faces.DeleteFaces(faceIndicesToDelete).



Thanks for the reference. This was a big help.


1 Like