# Change color of each model uploaded

**URL:** <https://discourse.slicer.org/t/change-color-of-each-model-uploaded/31966>\
**Category:** Support\
**Created:** [September 29, 2023, 3:04pm UTC](https://discourse.slicer.org/t/change-color-of-each-model-uploaded/31966 "2023-09-29T15:04:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CharNamIII](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/charnamiii/32/67678_2.png) [@CharNamIII](https://discourse.slicer.org/u/CharNamIII)\
**Post date:** [September 29, 2023, 3:04pm UTC](https://discourse.slicer.org/t/change-color-of-each-model-uploaded/31966/1 "2023-09-29T15:04:56Z")

</div>

Hi,

Is there a way to give each model a unique color when uploaded to 3DSlicer? They all come out the same color if I upload them all at once and changing them one by one takes a long time!

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [September 30, 2023, 1:23am UTC](https://discourse.slicer.org/t/change-color-of-each-model-uploaded/31966/2 "2023-09-30T01:23:19Z")

</div>

This is easy to do via scripting, and I don’t think there is a way through UI. Interestingly enough, I couldn’t find an example of changing a color of a model node in script repository. But ChatGPT has quite helpful with the question:  
`how can I change the color of a model node in 3D slicer with python?`

It gave me this non-functional (with extraneous stuff in it) example.

```auto
import slicer
import vtk

# Get the model node by name
model_node = slicer.util.getNodeByName("YourModelNodeName")

# Create a color table node
color_table_node = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLColorTableNode")

# Define the color (e.g., red)
color = vtk.vtkUnsignedCharArray()
color.SetNumberOfComponents(3)
color.InsertNextTuple3(255, 0, 0)

# Set the color of the model node
model_node.GetDisplayNode().SetColor(color_table_node.GetColorIndex(color))

# Update the 3D view
slicer.util.resetFiducialsMarkersColor()

```

But it has enough pointers. So it was easy change it into this, in which the model node is called A.

```auto
import slicer

# Get the model node by name
model_node = slicer.util.getNode("A")

# Set the color of the model node
model_node.GetDisplayNode().SetColor(255,255,0)

```

you can then modify this example with your models and change their colors as you which by specifying their RGB codes.

---

<div class="post-metadata">

**Author:** ![CharNamIII](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/charnamiii/32/67678_2.png) [@CharNamIII](https://discourse.slicer.org/u/CharNamIII)\
**Post date:** [September 30, 2023, 10:46am UTC](https://discourse.slicer.org/t/change-color-of-each-model-uploaded/31966/3 "2023-09-30T10:46:28Z")

</div>

Hi,

Thanks for this! Interesting way of using ChatGPT!
