# How to change color of 3d-cube inside 3D-View?

**URL:** <https://discourse.slicer.org/t/how-to-change-color-of-3d-cube-inside-3d-view/769>\
**Category:** Support\
**Created:** [July 26, 2017, 12:26pm UTC](https://discourse.slicer.org/t/how-to-change-color-of-3d-cube-inside-3d-view/769 "2017-07-26T12:26:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![AJ\_ZHU](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@AJ\_ZHU](https://discourse.slicer.org/u/AJ_ZHU)\
**Post date:** [July 26, 2017, 12:26pm UTC](https://discourse.slicer.org/t/how-to-change-color-of-3d-cube-inside-3d-view/769/1 "2017-07-26T12:26:37Z")

</div>

I am new to Slicer. I got a question:  
How to change color of 3D-cube inside 3D-view through python-interactor?  
Thanks a lot!  
Aijun

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [July 26, 2017, 4:17pm UTC](https://discourse.slicer.org/t/how-to-change-color-of-3d-cube-inside-3d-view/769/2 "2017-07-26T16:17:53Z")

</div>

I don’t think you can do that. But you can hide it and create your own:

```python
# Choose your color
RGB_COLOR = 0.2, 0.4, 0.8

# Hide the cube
v = slicer.util.getNode('View1')
v.SetBoxVisible(False)

# Create yours
cube = vtk.vtkCubeSource()
cube.SetXLength(200)
cube.SetYLength(200)
cube.SetZLength(200)
cube.Update()
cubePolyData = cube.GetOutput()

# Create a model with the cube and add it to scene
modelNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLModelNode')
modelNode.SetAndObservePolyData(cubePolyData)
modelNode.CreateDefaultDisplayNodes()
modelNode.SetName('My cube')

# Edit display properties
displayNode = modelNode.GetDisplayNode()
displayNode.SetLighting(False)
displayNode.SetColor(RGB_COLOR)
WIREFRAME = 1
displayNode.SetRepresentation(WIREFRAME)
displayNode.SetBackfaceCulling(False)

```

---

<div class="post-metadata">

**Author:** ![AJ\_ZHU](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@AJ\_ZHU](https://discourse.slicer.org/u/AJ_ZHU)\
**Post date:** [July 27, 2017, 6:03pm UTC](https://discourse.slicer.org/t/how-to-change-color-of-3d-cube-inside-3d-view/769/3 "2017-07-27T18:03:52Z")

</div>

Thanks you so much, Fernando!  
I do appreciate your help very well!

It worked well after I did a little bit change:  
#modelNode = slicer.mrmlScene.AddNewNodeByClass(‘vtkMRMLModelNode’)  
–\> modelNode = slicer.mrmlScene.AddNode(slicer.vtkMRMLModelNode())  
I am not sure of why AddNewNodeByClass was not there.

Thank you again! Great job!

regards,  
Aijun

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [July 27, 2017, 7:49pm UTC](https://discourse.slicer.org/t/how-to-change-color-of-3d-cube-inside-3d-view/769/4 "2017-07-27T19:49:10Z")

</div>

You can mark my answer so that it helps next person who gets in the thread for help.

> [@AJ\_ZHU](#):
>
> I am not sure of why AddNewNodeByClass was not there.

You probably have an old version of Slicer. I think the [commit](https://github.com/Slicer/Slicer/commit/f6df62e88ea90092c2080f012364cead65d41fef) that introduced that function is from May.

---

<div class="post-metadata">

**Author:** ![AJ\_ZHU](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@AJ\_ZHU](https://discourse.slicer.org/u/AJ_ZHU)\
**Post date:** [July 27, 2017, 7:51pm UTC](https://discourse.slicer.org/t/how-to-change-color-of-3d-cube-inside-3d-view/769/5 "2017-07-27T19:51:27Z")

</div>

Thanks a lot.  
I guess you are right, I am using an old one.

By the way, I am facing the new issue of the center. I got an model there, is there way to get the center of the model object so that I may get my cube-center matched?

Thanks in advance!  
Aijun

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [July 27, 2017, 7:56pm UTC](https://discourse.slicer.org/t/how-to-change-color-of-3d-cube-inside-3d-view/769/6 "2017-07-27T19:56:29Z")

</div>

Try `modelNode.GetPolyData().GetCenter()`.

---

<div class="post-metadata">

**Author:** ![AJ\_ZHU](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@AJ\_ZHU](https://discourse.slicer.org/u/AJ_ZHU)\
**Post date:** [July 30, 2017, 11:44pm UTC](https://discourse.slicer.org/t/how-to-change-color-of-3d-cube-inside-3d-view/769/7 "2017-07-30T23:44:53Z")

</div>

hi Fernando,  
Thanks a lot, But I am still stuck with how to get the modelNode.GetPolyData().GetCenter() working (I guess just because I am new). I am still not sure of the classes structures/config for the slicer view.

Best,  
Aijun

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [July 31, 2017, 12:03am UTC](https://discourse.slicer.org/t/how-to-change-color-of-3d-cube-inside-3d-view/769/8 "2017-07-31T00:03:43Z")

</div>

> [@AJ\_ZHU](#):
>
> I am still not sure of the classes structures/config for the slicer view.

I’m not sure I understand the problem. Can you please rephrase? What are you doing? What do you expect? What do you get?

---

<div class="post-metadata">

**Author:** ![AJ\_ZHU](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@AJ\_ZHU](https://discourse.slicer.org/u/AJ_ZHU)\
**Post date:** [August 7, 2017, 1:27am UTC](https://discourse.slicer.org/t/how-to-change-color-of-3d-cube-inside-3d-view/769/9 "2017-08-07T01:27:20Z")

</div>

Hi Fernando,  
sorry for a long time to get back here to check with your expertise on the slicer.  
Here is a snapshot:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/e/4e1b6efdabb2c3896289bf0ae773e8042135cdad.png)  
you see here, I get your idea of making a new cube scene but I have to no idea how to get my object and the cube sharing the same center.

Thanks a lot,  
Aijun

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [November 18, 2017, 3:24pm UTC](https://discourse.slicer.org/t/how-to-change-color-of-3d-cube-inside-3d-view/769/10 "2017-11-18T15:24:32Z")

</div>

I just saw your answer. Were you able to solve the problem?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 7, 2021, 12:13am UTC](https://discourse.slicer.org/t/how-to-change-color-of-3d-cube-inside-3d-view/769/11 "2021-06-07T00:13:00Z")

</div>

A post was split to a new topic: [How to change the size of the cube in 3D views](https://discourse.slicer.org/t/how-to-change-the-size-of-the-cube-in-3d-views/17983)
