# Access color table in CLI module

**URL:** <https://discourse.slicer.org/t/access-color-table-in-cli-module/318>\
**Category:** Development\
**Created:** [May 15, 2017, 9:56pm UTC](https://discourse.slicer.org/t/access-color-table-in-cli-module/318 "2017-05-15T21:56:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mirclem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mirclem/32/3356_2.png) [@mirclem](https://discourse.slicer.org/u/mirclem)\
**Post date:** [May 15, 2017, 9:56pm UTC](https://discourse.slicer.org/t/access-color-table-in-cli-module/318/1 "2017-05-15T21:56:58Z")

</div>

One more question…

I noticed that the colormaps have an attribute “reference” in the tag “table” but I couldn’t find a way to access it.

> ```
> <table hidden="true" type="color" reference="InputVolume">
> <name>ColorTable</name>
> <channel>input</channel>
> <longflag>color</longflag>
> <description><![CDATA[Color table to make labels to colors and objects]]></description>
> </table>
> 
> ```

I thought we could use the same method than for the other attributes like the [file extension](https://github.com/Slicer/Slicer/blob/master/Libs/MRML/CLI/vtkMRMLCommandLineModuleNode.cxx#L974). But there is no GetParameterReference(int, int) function and the vtkMRMLCommandLineModuleNode.GetModuleDescription() is not available for python. The only thing I found is vtkMRMLCommandLineModuleNode.GetModuleDescriptionAsString() but it needs a way to structure the string to be parsed.

Any thoughts?

---

<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:** [May 15, 2017, 11:54pm UTC](https://discourse.slicer.org/t/access-color-table-in-cli-module/318/2 "2017-05-15T23:54:41Z")

</div>

Colormap is an input to the CLI module. It is used for passing colormap with labelmap volumes. This allows the CLI to get label name corresponding to a voxel value.

---

<div class="post-metadata">

**Author:** ![mirclem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mirclem/32/3356_2.png) [@mirclem](https://discourse.slicer.org/u/mirclem)\
**Post date:** [May 16, 2017, 1:15pm UTC](https://discourse.slicer.org/t/access-color-table-in-cli-module/318/3 "2017-05-16T13:15:54Z")

</div>

Hi Andras, my question was more about how to get the labelmap node relative to a colormap given in a CLI command. I know it is possible in C++ but I could not find a way to do it in python.

---

<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:** [May 16, 2017, 1:36pm UTC](https://discourse.slicer.org/t/access-color-table-in-cli-module/318/4 "2017-05-16T13:36:54Z")

</div>

CLI infrastructure sets the labelmap node automatically from the colormap node that you set in the display node of the volume node (volumeNode-\>GetDisplayNode()-\>SetAndObserveColorNodeID(…)).

---

<div class="post-metadata">

**Author:** ![mirclem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mirclem/32/3356_2.png) [@mirclem](https://discourse.slicer.org/u/mirclem)\
**Post date:** [May 16, 2017, 2:05pm UTC](https://discourse.slicer.org/t/access-color-table-in-cli-module/318/5 "2017-05-16T14:05:20Z")

</div>

Actually, this is why this post was in the previous post, because there is a context behind that. I am not trying to run the CLI from the regular CLI infrastructure but I am trying to create the command, send it to a database and run it remotely.

I was able to access the colormap knowing the labelmap node:  
`saveNode(getNode('MyLabelMap').GetDisplayNode().GetColorNode(), "myPath.txt")`

But, in the [example of Model Maker](https://discourse.slicer.org/t/access-color-table-in-cli-module/318?u=mirclem), there is a `reference` attribute in the xml file. This attribute says which LabelMapNode looking for to get the colormap. And I can’t access the `reference` attribute.

---

<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:** [May 16, 2017, 2:15pm UTC](https://discourse.slicer.org/t/access-color-table-in-cli-module/318/6 "2017-05-16T14:15:34Z")

</div>

In the CLI you don’t get the reference attribute value, as MRML node IDs only make sense in a specific scene. Instead, you get the filename of the saved colormap node that is associated with the volume defined by reference attribute.

---

<div class="post-metadata">

**Author:** ![mirclem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mirclem/32/3356_2.png) [@mirclem](https://discourse.slicer.org/u/mirclem)\
**Post date:** [May 16, 2017, 3:44pm UTC](https://discourse.slicer.org/t/access-color-table-in-cli-module/318/7 "2017-05-16T15:44:03Z")

</div>

I noticed two different behaviors:

- If you parse the CLI parameters without having run the CLI before, the colormap parameter has an empty value.
- If you run the CLI and then try to parse the parameters, the colormap parameter has, as you said, the filename of the save colormap. (Which is enough for what I want)

I don’t really want to have to previously run the CLI and then generate a right command.

---

<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:** [May 16, 2017, 5:28pm UTC](https://discourse.slicer.org/t/access-color-table-in-cli-module/318/8 "2017-05-16T17:28:07Z")

</div>

CLI node is for running CLIs. If you don’t want to run a CLI then you can get the information directly from the nodes in the scene.

If you need a better solution then please describe what exactly you would like to achieve as an end result, and then we can help better in figuring out how to get there.

---

<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:** [May 16, 2017, 6:15pm UTC](https://discourse.slicer.org/t/access-color-table-in-cli-module/318/9 "2017-05-16T18:15:06Z")

</div>

2 posts were split to a new topic: [Running CLI modules on a remote server](https://discourse.slicer.org/t/running-cli-modules-on-a-remote-server/328)
