# How to prevent Slicer from "forgetting" slicer.util.loadColorTable after closing a scene

**URL:** <https://discourse.slicer.org/t/how-to-prevent-slicer-from-forgetting-slicer-util-loadcolortable-after-closing-a-scene/9932>\
**Category:** Development\
**Created:** [January 24, 2020, 1:10am UTC](https://discourse.slicer.org/t/how-to-prevent-slicer-from-forgetting-slicer-util-loadcolortable-after-closing-a-scene/9932 "2020-01-24T01:10:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vincent\_C](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/vincent_c/32/5759_2.png) [@Vincent\_C](https://discourse.slicer.org/u/Vincent_C)\
**Post date:** [January 24, 2020, 1:10am UTC](https://discourse.slicer.org/t/how-to-prevent-slicer-from-forgetting-slicer-util-loadcolortable-after-closing-a-scene/9932/1 "2020-01-24T01:10:43Z")

</div>

Hi all,

I am using **slicer.util.loadColorTable('c:/Users…)** in slicerrc.py to direct Slicer to load a custom color table file in a specified location. This works great, however, when I close the scene and “Add Data into the scene”, the option for my custom colour table no longer shows up in the drop-down menu. How can I prevent the table from disappearing after closing a scene?

Thanks

---

<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:** [January 24, 2020, 1:17am UTC](https://discourse.slicer.org/t/how-to-prevent-slicer-from-forgetting-slicer-util-loadcolortable-after-closing-a-scene/9932/2 "2020-01-24T01:17:06Z")

</div>

There is no standard way of storing label and color information in a volume file.

One option is to save the scene (containing the labelmap and color table) as a single .mrb file. Click on the package icon in the Save data dialog to toggle between single/multi-file saving.

Or, you can save the segmentation as a segmentation node (right-click the labelmap volume node to convert it to segmentation). Segmentation files are volume files that contain all segment names and color in custom fields.

---

<div class="post-metadata">

**Author:** ![Vincent\_C](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/vincent_c/32/5759_2.png) [@Vincent\_C](https://discourse.slicer.org/u/Vincent_C)\
**Post date:** [January 24, 2020, 1:23am UTC](https://discourse.slicer.org/t/how-to-prevent-slicer-from-forgetting-slicer-util-loadcolortable-after-closing-a-scene/9932/3 "2020-01-24T01:23:15Z")

</div>

Hi Andras,

Thanks for the reply. What if I were to use a script similar to that from [https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Create\_custom\_color\_table](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Create_custom_color_table) in slicerrc.py?:

```python
invertedocean = slicer.vtkMRMLColorTableNode()
invertedocean.SetTypeToUser()
invertedocean.SetNumberOfColors(256)
invertedocean.SetName("InvertedOcean")

for i in range(0,255):
    invertedocean.SetColor(i, 0.0, 1 - (i+1e-16)/255.0, 1.0, 1.0)

slicer.mrmlScene.AddNode(invertedocean)

```

It also gives the option to choose the InvertedOcean color but disappears after closing a scene. Can the script be modified so that the color is saved?

Thanks

---

<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:** [January 24, 2020, 1:28am UTC](https://discourse.slicer.org/t/how-to-prevent-slicer-from-forgetting-slicer-util-loadcolortable-after-closing-a-scene/9932/4 "2020-01-24T01:28:58Z")

</div>

There are many options to keep a node around but probably the simplest is to make it a singleton node (one instance per scene, identified by node type and singleton tag, not deleted when scene is closed) by calling `invertedocean.SetSingletonTag("Vincent.InvertedOcean")`.

---

<div class="post-metadata">

**Author:** ![Vincent\_C](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/vincent_c/32/5759_2.png) [@Vincent\_C](https://discourse.slicer.org/u/Vincent_C)\
**Post date:** [January 24, 2020, 1:38am UTC](https://discourse.slicer.org/t/how-to-prevent-slicer-from-forgetting-slicer-util-loadcolortable-after-closing-a-scene/9932/5 "2020-01-24T01:38:30Z")

</div>

Hi Andras,

This sounds like a possible solution! Say I am using the command: slicer.util.loadColorTable(‘c:/Users/Vince/My\_Color\_Table.ctbl’) - Can I also use the singleton tag to keep the node corresponding vtkMRMLColorTableNode around?

Thanks

---

<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:** [January 24, 2020, 1:40am UTC](https://discourse.slicer.org/t/how-to-prevent-slicer-from-forgetting-slicer-util-loadcolortable-after-closing-a-scene/9932/6 "2020-01-24T01:40:54Z")

</div>

Yes, you can make any node singleton by setting its SingletonTag.

---

<div class="post-metadata">

**Author:** ![Vincent\_C](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/vincent_c/32/5759_2.png) [@Vincent\_C](https://discourse.slicer.org/u/Vincent_C)\
**Post date:** [January 24, 2020, 1:47am UTC](https://discourse.slicer.org/t/how-to-prevent-slicer-from-forgetting-slicer-util-loadcolortable-after-closing-a-scene/9932/7 "2020-01-24T01:47:16Z")

</div>

Oh that is great! I am a novice user, can you give me an example of how to do that if my node is as so:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/d/9dd7c292d292a7e5c0294003ad2089c4c1a328aa.png)

---

<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:** [January 24, 2020, 1:57am UTC](https://discourse.slicer.org/t/how-to-prevent-slicer-from-forgetting-slicer-util-loadcolortable-after-closing-a-scene/9932/8 "2020-01-24T01:57:34Z")

</div>

`slicer.util.load...` methods return the loaded node, so you can call `SetSingletonTag` on that.
