Loading vtkMRMLTextNode with arbitrary file name extension

Is it possible to load a vtkMRMLTextNode with a file extension other than txt, xml or json? For example, I want to load a text file with the extension “.inp” but Slicer only shows the option to load it as a volume.

Allowing a reader to accept arbitrary file extension leads to user confusion, so I would try to avoid doing that. Fortunately, it is not needed anymore because it is really easy to create a scripted reader for any file format.

You can add a few ten lines of Python script to any of your Python scripted modules that specify that the module can read of .inp files. When the user tries to open such a file then the reader can inspect the file (e.g., read the first few lines of the file to see if is indeed a file it can handle) and then offer it for reading. You can similarly specify a writer plugin. See complete examples here.

1 Like

That’s perfect! I thought this was only possible using C++.

1 Like