Load vtp files in slicer

Dear developers,
I want to load the output vtp files generated back to slicer, the code I write is as following:
#Load the generated anatomical tracts back into Slicer
for file_name in os.listdir(AnatomicalTractsFolder):
# Check whether the file extension is VTP
if file_name.endswith(“.vtp”):
# Build the full path of the file
file_path = os.path.join(AnatomicalTractsFolder, file_name)
# load vtp in slicer
loaded_model_node = slicer.util.loadModel(file_path)
However, it failed:

Best wishes,
Joshua

It looks like that vtp file is empty. Probably this is flagged as an error in VTK. You can wrap your loadModel call in a try/except that the file didn’t load.

It is likely that older VTK versions silently accepted empty files but the I/O was reworked. I ran into an issue like this when trying lo save empty files:

1 Like