# Color desired mesh faces

**URL:** <https://discourse.mcneel.com/t/color-desired-mesh-faces/78268>\
**Category:** Rhino Developer\
**Tags:** rhinocommon\
**Created:** [February 4, 2019, 12:45pm UTC](https://discourse.mcneel.com/t/color-desired-mesh-faces/78268 "2019-02-04T12:45:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pouryatorabi](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/pouryatorabi/32/190755_2.png) [@pouryatorabi](https://discourse.mcneel.com/u/pouryatorabi)\
**Post date:** [February 4, 2019, 12:45pm UTC](https://discourse.mcneel.com/t/color-desired-mesh-faces/78268/1 "2019-02-04T12:45:49Z")

</div>

Hi every one.  
I have a mesh file in Rhino and just want to change the color of some specific mesh faces to red. First I tried to see what is the color of the mesh with:

> foreach (Color color in mesh.VertexColors)  
> {  
> Debug.WriteLine(“Color is :”);  
> Debug.WriteLine(color);  
> }  
> It shows nothing as if the mesh is colorless. Then I tried to color the whole mesh with:  
> System.Drawing.Color colors = new System.Drawing.Color[mesh.Vertices.Count];  
> System.Drawing.Color colors = new System.Drawing.Color[mesh.Vertices.Count];  
> for (int i = 0; i \< mesh.Vertices.Count; i++)  
> {  
> colors[i] = System.Drawing.Color.Red;  
> }  
> mesh.VertexColors.SetColors(colors);

And then again tried to see if the colors are set with:

> foreach (Color color in mesh.VertexColors)  
> {  
> Debug.WriteLine(“Color is :”);  
> Debug.WriteLine(color);  
> }  
> It prints the red color at the console but the color of the mesh won’t change in the Render. What should I do to change the color in the render?

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/557284_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [February 4, 2019, 12:49pm UTC](https://discourse.mcneel.com/t/color-desired-mesh-faces/78268/2 "2019-02-04T12:49:31Z")

</div>

Have you replaced the mesh object in the document?

Also, I don’t think mesh vertices’ color will show in Render mode. You may need a material.

---

<div class="post-metadata">

**Author:** ![pouryatorabi](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/pouryatorabi/32/190755_2.png) [@pouryatorabi](https://discourse.mcneel.com/u/pouryatorabi)\
**Post date:** [February 4, 2019, 12:53pm UTC](https://discourse.mcneel.com/t/color-desired-mesh-faces/78268/3 "2019-02-04T12:53:40Z")

</div>

Now that you have asked me I saw that I have made an instance of the object into my mesh and add the color to that but since I didn’t want to create another object to my doc, I didn’t add the instance to doc.

Now I just added the mesh to doc and redraw it. The color is applied to the mesh but can not see it in render. How should I create a material?

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/557284_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [February 4, 2019, 1:41pm UTC](https://discourse.mcneel.com/t/color-desired-mesh-faces/78268/4 "2019-02-04T13:41:09Z")

</div>

1. make sure that the original mesh is not overlapping with the new colored mesh, have you done a _replacement_?
2. Using the code below, I can add a quad-face mesh to the document and see it in Shaded and Rendered mode (but not in Raytraced mode)

```auto
Mesh m = new Mesh();
m.Vertices.AddVertices(new []{
  new Point3d(0, 0, 0), 
  new Point3d(0, 1, 0), 
  new Point3d(1, 1, 0),
  new Point3d(1, 0, 0)
});

m.Faces.AddFace(0, 1, 2, 3);

m.VertexColors.AddRange(new Color[]{Color.Red, Color.Green, Color.Blue, Color.Gray });
doc.Objects.Add(m);
return Result.Success;

```

![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/b/b/bbaaf2329aa361727a27993be6138c6ef1f7dc64.png)

---

<div class="post-metadata">

**Author:** ![pouryatorabi](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/pouryatorabi/32/190755_2.png) [@pouryatorabi](https://discourse.mcneel.com/u/pouryatorabi)\
**Post date:** [February 4, 2019, 2:04pm UTC](https://discourse.mcneel.com/t/color-desired-mesh-faces/78268/5 "2019-02-04T14:04:13Z")

</div>

Thank you for your reply, since I wanted to make a constrain from multiple parts for mouse click, I appended all the objects to a mesh and used the mesh as a constrain. So I didn’t need any feature from it. Now I want to change the color of some mesh faces so I think I should delete the original objects and add the created mesh to the doc. Right?
