# Access AnnotationROINode without knowing the ID

**URL:** <https://discourse.slicer.org/t/access-annotationroinode-without-knowing-the-id/16777>\
**Category:** Development\
**Tags:** python\
**Created:** [March 26, 2021, 1:34pm UTC](https://discourse.slicer.org/t/access-annotationroinode-without-knowing-the-id/16777 "2021-03-26T13:34:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![pll\_llq](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pll_llq/32/9408_2.png) [@pll\_llq](https://discourse.slicer.org/u/pll_llq)\
**Post date:** [March 26, 2021, 1:34pm UTC](https://discourse.slicer.org/t/access-annotationroinode-without-knowing-the-id/16777/1 "2021-03-26T13:34:06Z")

</div>

Hi 🖖

I’m in python and when I create a volume rendering for a scalar volume node using `UpdateDisplayNodeFromVolumeNode` from `modules.volumerendering.logic`, the AnnotationROINode is created automatically.

I want to rename the default AnnotationROINode so that when I work with many volumes their ROI nodes are clearly identifiable in the Subject Hierarchy view.

I use this snippet from the docs to create the volume rendering:

```python
volumeNode = myAwesomeVolumeNode

logic = slicer.modules.volumerendering.logic()

displayNode = logic.CreateVolumeRenderingDisplayNode()
displayNode.UnRegister(logic)
slicer.mrmlScene.AddNode(displayNode)
volumeNode.AddAndObserveDisplayNodeID(displayNode.GetID())

logic.UpdateDisplayNodeFromVolumeNode(displayNode, volumeNode)

freshlyCreatedDefaultAnnotationROINode = ...

```

I can see the connection to the AnnotationROI in the Data module if I select the Volume Node.  
How do I see this link from python? Is there a way to access the AnnotationROINode without searching for it explicitly by id, name or classname?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/1/a1af902a66c52524d3aa697183647dc46bf59c03.png)

---

<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:** [March 26, 2021, 6:05pm UTC](https://discourse.slicer.org/t/access-annotationroinode-without-knowing-the-id/16777/2 "2021-03-26T18:05:31Z")

</div>

Looks like you can create the ROI yourself and pass it in. You could create the volume property and ROI with logical names before calling the method.

[https://apidocs.slicer.org/master/classvtkSlicerVolumeRenderingLogic.html#a0dd5b03b39e2f70a3edadd7b1c41cbf9](https://apidocs.slicer.org/master/classvtkSlicerVolumeRenderingLogic.html#a0dd5b03b39e2f70a3edadd7b1c41cbf9)

---

<div class="post-metadata">

**Author:** ![pll\_llq](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pll_llq/32/9408_2.png) [@pll\_llq](https://discourse.slicer.org/u/pll_llq)\
**Post date:** [March 26, 2021, 6:23pm UTC](https://discourse.slicer.org/t/access-annotationroinode-without-knowing-the-id/16777/3 "2021-03-26T18:23:54Z")

</div>

Thanks @pieper, I’ve tried calling the `UpdateDisplayNodeFromVolumeNode` but it appeared to me that it didn’t change anything in the scene and when I tried to turn on volume rendering from the UI the “AnnotationROI\_3” still appeared.  
As another similar workaround I’ve used for now is creating, naming and registering the node manually using the code like in the attached snippet. I probably miss attaching the roi to the volume because despite that the volume rendering works as expected I create these nodes manually I can’t see the “link” in the data module widget.

here’s the snippet

```python
myVolume = pNode.GetNodeReference('myVolume')

ROINode = slicer.vtkMRMLAnnotationROINode()
ROINode.SetName('myVolumeAnnotationROI')
ROINode.Initialize(slicer.mrmlScene)
ROINode.SetRadiusXYZ(50, 50, 100)
ROINode.SetInteractiveMode(1)
ROINode.SetDisplayVisibility(1)

volumeRenderingDisplayNode = slicer.modules.volumerendering.logic().CreateDefaultVolumeRenderingNodes(myVolume)
propertyNode = volumeRenderingDisplayNode.GetVolumePropertyNode()

volumeRenderingDisplayNode.SetAndObserveROINodeID(ROINode.GetID())

volumeRenderingDisplayNode.SetCroppingEnabled(1)
volumeRenderingDisplayNode.VisibilityOn()

```

I’ve seen that the `AnnotationROINode` has a `.GetVolumeNodeID` method that should [“Get/Set for the volume node ID associated with this ROI”](http://apidocs.slicer.org/master/classvtkMRMLAnnotationROINode.html#a7334c9c43ffc2d6736bdf1e5d4b58c34) but it’s empty by default. Do I need to use the setter here to link the ROI with the volume?

---

<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:** [March 26, 2021, 7:32pm UTC](https://discourse.slicer.org/t/access-annotationroinode-without-knowing-the-id/16777/4 "2021-03-26T19:32:56Z")

</div>

> [@pll\_llq](#):
>
> Do I need to use the setter here to link the ROI with the volume?

I’m not sure about that, I haven’t tried.

But do you ever add `ROINode` to the scene? If not probably `ROINode.GetID()` returns null.

You might switch to creating the node with `slicer.mrmlScene.AddNewNodeByClass` so you know it’s in the scene with a valid id.

---

<div class="post-metadata">

**Author:** ![pll\_llq](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pll_llq/32/9408_2.png) [@pll\_llq](https://discourse.slicer.org/u/pll_llq)\
**Post date:** [March 26, 2021, 7:34pm UTC](https://discourse.slicer.org/t/access-annotationroinode-without-knowing-the-id/16777/5 "2021-03-26T19:34:20Z")

</div>

> [@pieper](#):
>
> You might switch to creating the node with `slicer.mrmlScene.AddNewNodeByClass` so you know it’s in the scene with a valid id.

Thanks, will try this.

---

<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 11, 2021, 4:57am UTC](https://discourse.slicer.org/t/access-annotationroinode-without-knowing-the-id/16777/6 "2021-05-11T04:57:58Z")

</div>

Note that we are phasing out Annotations module. If you are building anything new then you may consider using markups ROI instead of annotations ROI. Markups ROI has a number of important advantages, such as you can rotate it without applying a transform.

---

<div class="post-metadata">

**Author:** ![pll\_llq](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pll_llq/32/9408_2.png) [@pll\_llq](https://discourse.slicer.org/u/pll_llq)\
**Post date:** [May 11, 2021, 5:21am UTC](https://discourse.slicer.org/t/access-annotationroinode-without-knowing-the-id/16777/7 "2021-05-11T05:21:08Z")

</div>

Yes I remember that you mentioned thin in the call. What’s the timeline for such depreciation and are there isage examples in the script repository?

---

<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 11, 2021, 5:43am UTC](https://discourse.slicer.org/t/access-annotationroinode-without-knowing-the-id/16777/8 "2021-05-11T05:43:56Z")

</div>

Probably we will remove annotations module in a year or so. You can find markups manipulation examples in the [script repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#markups) and we can add more examples as questions are asked.

---

<div class="post-metadata">

**Author:** ![pll\_llq](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pll_llq/32/9408_2.png) [@pll\_llq](https://discourse.slicer.org/u/pll_llq)\
**Post date:** [May 11, 2021, 5:49am UTC](https://discourse.slicer.org/t/access-annotationroinode-without-knowing-the-id/16777/9 "2021-05-11T05:49:15Z")

</div>

Thanks, will look deeper into it.

By the way, will removal of annotations module break older extensions and custom apps that use it?

---

<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 11, 2021, 1:42pm UTC](https://discourse.slicer.org/t/access-annotationroinode-without-knowing-the-id/16777/10 "2021-05-11T13:42:24Z")

</div>

> [@pll\_llq](#):
>
> By the way, will removal of annotations module break older extensions and custom apps that use it?

Yes, that’s why we remove annotations module slowly, in several phases. We have already stopped developing and fixing Annotations module and stated that the module is deprecated. Next step is to update all core modules and extensions to support markups as well, then change modules to create markups node instead by default, then hide Annotations module GUI, and finally remove the module completely. The last step will probably only happen in a few years when some Slicer changes would require too much work to keep Annotations module working. See current plan in the [Roadmap](https://github.com/Slicer/Slicer/wiki/Roadmap).
