# How to see all loaded data in Scene via Python

**URL:** <https://discourse.slicer.org/t/how-to-see-all-loaded-data-in-scene-via-python/27520>\
**Category:** Development\
**Created:** [January 28, 2023, 9:32pm UTC](https://discourse.slicer.org/t/how-to-see-all-loaded-data-in-scene-via-python/27520 "2023-01-28T21:32:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![michabermoy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/michabermoy/32/16003_2.png) [@michabermoy](https://discourse.slicer.org/u/michabermoy)\
**Post date:** [January 28, 2023, 9:32pm UTC](https://discourse.slicer.org/t/how-to-see-all-loaded-data-in-scene-via-python/27520/1 "2023-01-28T21:32:25Z")

</div>

How can I obtain all loaded data in the scene via python, if such data exists? I need to create a conditional that only runs a certain function if the scene already has some data, otherwise the user is prompted to load data.

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

Also what are the different data types that can be loaded by the user? For example, scene, volume, sequence, and transforms can be loaded by the user via the slicer.util.load… function, but I do not know all the possible types/functions

---

<div class="post-metadata">

**Author:** ![ebrahim](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ebrahim/32/13403_2.png) [@ebrahim](https://discourse.slicer.org/u/ebrahim)\
**Post date:** [January 29, 2023, 4:15pm UTC](https://discourse.slicer.org/t/how-to-see-all-loaded-data-in-scene-via-python/27520/2 "2023-01-29T16:15:40Z")

</div>

> [@michabermoy](#):
>
> Also what are the different data types that can be loaded by the user? For example, scene, volume, sequence, and transforms can be loaded by the user via the slicer.util.load… function, but I do not know all the possible types/functions

See the inheritance diagram at the top of this page which shows all the descendants of `vtkMRMLStorableNode`:  
[https://apidocs.slicer.org/master/classvtkMRMLStorableNode.html](https://apidocs.slicer.org/master/classvtkMRMLStorableNode.html)  
There are other nodes that can be in a scene that serve various purposes, but I guess the storable nodes are “data types” that could be saved/loaded.  
Another possibility is to look at all `vtkMRMLDisplayableNode`s:  
[https://apidocs.slicer.org/master/classvtkMRMLDisplayableNode.html](https://apidocs.slicer.org/master/classvtkMRMLDisplayableNode.html)  
which includes only the ones the user can “see” in the scene.  
To summarize: Markups, models, volumes, segmentations, and transforms.

> [@michabermoy](#):
>
> How can I obtain all loaded data in the scene via python, if such data exists? I need to create a conditional that only runs a certain function if the scene already has some data, otherwise the user is prompted to load data.

For checking if the subject hierarchy (the list displayed in your screenshot) has any items in it, I think this works:

```py
slicer.mrmlScene.GetSubjectHierarchyNode().GetNumberOfItems()

```

For listing all nodes in the scene of a certain type (which includes many that don’t show up in the subject hierarchy) you can do something like

```py
list(slicer.mrmlScene.GetNodesByClass('vtkMRMLDisplayableNode'))

```

for example to get a list of all the `vtkMRMLDisplayableNode`s

---

<div class="post-metadata">

**Author:** ![RafaelPalomar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafaelpalomar/32/1436_2.png) [@RafaelPalomar](https://discourse.slicer.org/u/RafaelPalomar)\
**Post date:** [February 1, 2023, 11:37am UTC](https://discourse.slicer.org/t/how-to-see-all-loaded-data-in-scene-via-python/27520/3 "2023-02-01T11:37:19Z")

</div>

> [@michabermoy](#):
>
> How can I obtain all loaded data in the scene via python, if such data exists? I need to create a conditional that only runs a certain function if the scene already has some data, otherwise the user is prompted to load data.

For this use case, I would rather observe the MRML scene for new nodes added and react to the first addition (you can also filter the type of nodes you want to consider), then you can remove the observer or simply ignore subsequent event triggers.

> [@michabermoy](#):
>
> Also what are the different data types that can be loaded by the user? For example, scene, volume, sequence, and transforms can be loaded by the user via the slicer.util.load… function, but I do not know all the possible types/functions

There are a lot of data types that the user can load, and this also depends on the extensions installed by the user. `slicer.util.load..` are utility functions to load the most commonly used types, but they don’t represent the whole extent of possibilities. In the approach described (observing the MRML Scene) above you will be “notified” for any data type loaded, even data supported by other modules.
