Changing a Mesh Face color

I been trying to change the color of just a mesh face… without any luck.

(I saw the example to change the color of an entire object … )

myMeshObj = Rhino.DocObjects.Tables.ObjectTable.Find(doc.Objects, ID)
myMeshes = myMeshObj.GetMeshes(Rhino.Geometry.MeshType.Default)
myMeshes[0].VertexColors.SetColor( myMeshes[0].Faces[0], System.Drawing.Color.Black )

But was trying to make all the faces different colors…
Any Points what I am missing here?

If you are going specify mesh vertex colors, you MUST specify the color of every vertex.

Is that with

When I add the mesh makes my box red

but if I got to modify them
myMeshes[0].VertexColors.SetColor(0, 0, 0, 0)
myMeshes[0].VertexColors.SetColor(1, 0, 0, 0)
myMeshes[0].VertexColors.SetColor(2, 0, 0, 0)
myMeshes[0].VertexColors.SetColor(3, 0, 0, 0)
myMeshes[0].VertexColors.SetColor(4, 0, 0, 0)
myMeshes[0].VertexColors.SetColor(5, 0, 0, 0)
myMeshes[0].VertexColors.SetColor(6, 0, 0, 0)
myMeshes[0].VertexColors.SetColor(7, 0, 0, 0)
to black it stays red even if I have a myMeshObj.CommitChanges() do I have to commit the changes to the mesh itself somehow?

I am forcing the doc to redraw, but is there something else that is needed then?

1.) Get the mesh.
2.) Make a copy of it.
3.) Modify the copy.
4.) Replace the original with the copy using Rhino.RhinoDoc.Objects.Replace.

Does this help?


Rhino.DocObjects.Tables.ObjectTable.Replace(Rhino.RhinoDoc.ActiveDoc.Objects, pID, myMeshes[0])


I’m not sure, if it’s a bug, but it seems to me to be.
I can change color of specified vertices of the mesh by rs.MeshVertexColors(mesh_id, colors).
But when I use rs.MeshVertexColors(mesh_id, None) it doesn’t remove the color from the mesh as intended.
Also when I use only the mesh.VertexColors.Clear() command, it doesn’t change anything.

Can anyone of you reproduce this?


Yes, it looks like there needs to be a call to scriptcontext.doc.Objects.Replace. I’ll get this on the to-do list for the next Rhino service release.

Thanks @dale, this works.