# Knowing the node allowed file extensions while saving

**URL:** <https://discourse.slicer.org/t/knowing-the-node-allowed-file-extensions-while-saving/15779>\
**Category:** Support\
**Tags:** python\
**Created:** [February 1, 2021, 6:50pm UTC](https://discourse.slicer.org/t/knowing-the-node-allowed-file-extensions-while-saving/15779 "2021-02-01T18:50:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [February 1, 2021, 6:50pm UTC](https://discourse.slicer.org/t/knowing-the-node-allowed-file-extensions-while-saving/15779/1 "2021-02-01T18:50:54Z")

</div>

while using saveNode I need to provide the correct file extension, however I failed to know the node class type to create the proper if sentence.  
Example:

```nohighlight
node is vtkMRMLScalarVolumeNode => filename ends in .nrrd
node is vtkMRMLSegmentationNode => filename ends in .seg.nrrd
node is vtkMRMLTransformNode => filename ends in .h5

```

How to achive 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:** [February 1, 2021, 7:01pm UTC](https://discourse.slicer.org/t/knowing-the-node-allowed-file-extensions-while-saving/15779/2 "2021-02-01T19:01:16Z")

</div>

Supported file extension also depends on the associated node content (for example, if master representation of a segmentation if closed surface then file extension will be .seg.vtm). You can get the list is usable file type descriptions and file extensions from the storage node:

```python
fileTypes = storageNode.GetSupportedWriteFileTypes()
fileExtensions = vtk.vtkStringArray()
storageNode.GetFileExtensionsFromFileTypes(fileTypes, fileExtensions);
print(fileExtensions.GetValue(0))

```

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [February 1, 2021, 7:11pm UTC](https://discourse.slicer.org/t/knowing-the-node-allowed-file-extensions-while-saving/15779/3 "2021-02-01T19:11:51Z")

</div>

So it is as easy as `storageNode=node.GetStorageNode()` to get the storage Node?

---

<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:** [February 1, 2021, 7:15pm UTC](https://discourse.slicer.org/t/knowing-the-node-allowed-file-extensions-while-saving/15779/4 "2021-02-01T19:15:36Z")

</div>

Yes you can get the storage node from the data node like that. If you are not sure if the data node has a storage node already then call `node.AddDefaultStorageNode()` before (it is safe to always call it because the method simply does not do anything if the data node has a storage node already).

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [February 1, 2021, 7:17pm UTC](https://discourse.slicer.org/t/knowing-the-node-allowed-file-extensions-while-saving/15779/5 "2021-02-01T19:17:54Z")

</div>

Although this solves my problem, the original question (knowing the node class programatically) I think stills open for another possible cases

---

<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:** [February 1, 2021, 7:26pm UTC](https://discourse.slicer.org/t/knowing-the-node-allowed-file-extensions-while-saving/15779/6 "2021-02-01T19:26:28Z")

</div>

> [@Alex\_Vergara](#):
>
> the original question (knowing the node class programatically) I think stills open for another possible cases

What is the information that you are still not sure how to get programmatically?

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [February 1, 2021, 7:53pm UTC](https://discourse.slicer.org/t/knowing-the-node-allowed-file-extensions-while-saving/15779/7 "2021-02-01T19:53:54Z")

</div>

given a node obtaing its class (ex vtkMRMLScalarVolumeNode)

---

<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:** [February 1, 2021, 7:55pm UTC](https://discourse.slicer.org/t/knowing-the-node-allowed-file-extensions-while-saving/15779/8 "2021-02-01T19:55:33Z")

</div>

You can get a node’s class name by calling `node.GetClassName()`.
