Knowing the node allowed file extensions while saving

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:

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?

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:

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

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

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).

1 Like

Although this solves my problem, 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?

given a node obtaing its class (ex vtkMRMLScalarVolumeNode)

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

1 Like