# Get the MRML ID of the volume being viewed through a python script

**URL:** <https://discourse.slicer.org/t/get-the-mrml-id-of-the-volume-being-viewed-through-a-python-script/34620>\
**Category:** Support\
**Tags:** python\
**Created:** [February 29, 2024, 5:55pm UTC](https://discourse.slicer.org/t/get-the-mrml-id-of-the-volume-being-viewed-through-a-python-script/34620 "2024-02-29T17:55:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![petit223](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@petit223](https://discourse.slicer.org/u/petit223)\
**Post date:** [February 29, 2024, 5:55pm UTC](https://discourse.slicer.org/t/get-the-mrml-id-of-the-volume-being-viewed-through-a-python-script/34620/1 "2024-02-29T17:55:58Z")

</div>

I want to get the MRML ID of the volume being viewed on the interface through a python script

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/1/014cfd597bfd3628a6a9d4107fb469b453bea1a7.png)  
For example, now I want to get the MRML ID of “20005: Screen Save” through python code, which is ‘vtkMRMLScalarVolumeNode133’  
I tried using `slicer.app.applicationLogic().GetSelectionNode().GetActiveVolumeID()` but the result is not what I want.  
If anyone can help me I will be very grateful !!

---

<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 29, 2024, 7:29pm UTC](https://discourse.slicer.org/t/get-the-mrml-id-of-the-volume-being-viewed-through-a-python-script/34620/2 "2024-02-29T19:29:59Z")

</div>

The Data module lets you set all at once, but each slice view can have different data, so you can look up each one individually:

```auto
slicer.app.layoutManager().sliceWidget("Red").mrmlSliceCompositeNode().GetBackgroundVolumeID()

```

(get the list of view names with `slicer.app.layoutManager().sliceViewNames()`)

---

<div class="post-metadata">

**Author:** ![petit223](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@petit223](https://discourse.slicer.org/u/petit223)\
**Post date:** [March 1, 2024, 1:12pm UTC](https://discourse.slicer.org/t/get-the-mrml-id-of-the-volume-being-viewed-through-a-python-script/34620/3 "2024-03-01T13:12:39Z")

</div>

Thank you very much !! I successfully got the ID I wanted.  
but I would also like to know how you came to know this code. I am an engineering student and am developing a 3D Slicer plug-in.  
thanks again for your kindness.

---

<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 1, 2024, 2:21pm UTC](https://discourse.slicer.org/t/get-the-mrml-id-of-the-volume-being-viewed-through-a-python-script/34620/4 "2024-03-01T14:21:54Z")

</div>

> [@petit223](#):
>
> I would also like to know how you came to know this code

I had the advantage that I was one of the authors for that part of the code.

But in general, when I need to figure out how some Slicer code works I follow the method described here:

[https://slicer.readthedocs.io/en/latest/developer\_guide/python\_faq.html#how-to-find-a-python-function-for-any-slicer-features](https://slicer.readthedocs.io/en/latest/developer_guide/python_faq.html#how-to-find-a-python-function-for-any-slicer-features)

It also helps to read through the script repository, extensions, and other parts of the code just to learn what’s possible.
