# How to programmatically set Terminology Name and Category for vtkMRMLSegmentationNode?

**URL:** <https://discourse.slicer.org/t/how-to-programmatically-set-terminology-name-and-category-for-vtkmrmlsegmentationnode/41504>\
**Category:** Development\
**Tags:** segmentation, python\
**Created:** [February 5, 2025, 2:18am UTC](https://discourse.slicer.org/t/how-to-programmatically-set-terminology-name-and-category-for-vtkmrmlsegmentationnode/41504 "2025-02-05T02:18:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![baderstine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/baderstine/32/79333_2.png) [@baderstine](https://discourse.slicer.org/u/baderstine)\
**Post date:** [February 5, 2025, 2:18am UTC](https://discourse.slicer.org/t/how-to-programmatically-set-terminology-name-and-category-for-vtkmrmlsegmentationnode/41504/1 "2025-02-05T02:18:28Z")

</div>

Operating system: MacOS 15.3  
Slicer version: 5.6.2

In my slicer extension, I am loading image and label (segmentation) volumes from a database. I have figured out how to load a custom terminology json file when the extension is loaded:

```auto
# Placed in extension's __init__ function
        path = self.resourcePath("Terminologies/terminologyfilename.json")
        tlogic = slicer.modules.terminologies.logic()
        terminologyName = tlogic.LoadTerminologyFromFile(path)

```

I also created color table files to use when loading in segmentations:

```auto
color_table_name = "some name"
script_path = os.path.dirname(os.path.abspath( __file__ )) # returns path to this file (volume.py)
color_file = os.path.join(script_path,"..","<module name>","Resources","Terminologies",f"{color_table_name}.txt")
color_table_node = slicer.util.loadColorTable(color_file)

ref_node = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLLabelMapVolumeNode")
<load label data into ref_node>
ref_node.CreateDefaultDisplayNodes()
ref_node.GetDisplayNode().SetAndObserveColorNodeID(color_table_node.GetID())
seg_node = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(ref_node, seg_node)
seg_node.GetDisplayNode().SetAndObserveColorNodeID(color_table_node.GetID())
seg_node.SetReferenceImageGeometryParameterFromVolumeNode(ref_node)
slicer.mrmlScene.RemoveNode(ref_node)

```

I’m wondering if there is some way for me to set the default terminology name and category for seg\_node in the above code so that when a user opens the Segment Editor for this segmentation node, adds a new segment, then double clicks on the Segment Color box (which brings up the Terminology selection window), my preferred Terminology, and Category are pre-selected, and all the user needs to do is pick the correct Property Type to assign to this segment?

Is there something like:  
seg\_node.SetDefaultTerminology()  
seg\_node.SetDefaultTerminologyCategory(\<Category.CodeMeaning\>)  
?

It feels like I’m doing something wrong or inefficient by loading BOTH a custom terminology file AND custom colortables which essentially map the exact same IDs, Names, and RGB/opacity values to individual segments/labels in different ways… but from all I can read/find this is the way?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [February 10, 2025, 4:49pm UTC](https://discourse.slicer.org/t/how-to-programmatically-set-terminology-name-and-category-for-vtkmrmlsegmentationnode/41504/2 "2025-02-10T16:49:38Z")

</div>

There was a lot of discussion of color tables and terminologies at the recent Project Week. It would be great if you could review the pending pull request and see if that addresses your concerns.

> **[Project Description](https://projectweek.na-mic.org/PW42_2025_GranCanaria/Projects/InfrastructureForCustomTerminologyAndColorTablesInSlicer/)**
>
> Website for NA-MIC Project Weeks

> <https://github.com/Slicer/Slicer/pull/8112>
>
> \- Add CSV file format support for color tables
> - Refactoring of storing color… properties in color node
> - Save terminology columns into color table CSV file
> - Implement color table terminology CSV reading
> \- Terminology manual editing from Colors module
> \- Move Colors widget classes into Colors module
> - The Colors module related widget classes have been in Libs/MRML/Widgets, but that way they cannot possibly use Terminology features. They need to be moved to the Colors module to facilitate this
> - Classes in Testing and DesignerPlugins folders using the moved classes have also been moved to Colors module
> - Remove FileName member from vtkMRMLColorNode, as it was not used (moreover, there were comments explaining why it is not used)
> \- Create terminology editor widgets for editing from item delegate
> \- Add functions to color node for get/set terminology as/from string (also add GetColorNameAutoGenerated)
> \- Style fixes
> \- Select terminology Colors module from the Terminologies column
> \- Terminology contexts from color nodes are offered in terminology context selector
> \- Add new color table node and entry buttons to Colors module
> \- Add export to color table function to Segment Editor
> 
> Re #6975, #7593
> 
> @muratmaga
> 
> 
> https://github.com/user-attachments/assets/43fc0943-0f9f-4d90-bccc-7d463e90b7bb
> 
> 
> https://github.com/user-attachments/assets/40412bd2-e73e-46ca-bf30-fd49f382290f
> 
> 
> https://github.com/user-attachments/assets/3c7b3d3f-b9bb-40f4-a78c-c8158345a9e2

---

<div class="post-metadata">

**Author:** ![baderstine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/baderstine/32/79333_2.png) [@baderstine](https://discourse.slicer.org/u/baderstine)\
**Post date:** [February 10, 2025, 5:13pm UTC](https://discourse.slicer.org/t/how-to-programmatically-set-terminology-name-and-category-for-vtkmrmlsegmentationnode/41504/3 "2025-02-10T17:13:17Z")

</div>

That’s a very extensive pull request on a code base that I am not familiar with at all. From what I’ve read in the comments, it is possible that it does address my concern but I cannot be sure until I’ve actually run my custom module code against it.
