Default format and compress

Hi
I used 3d slicer to segment organs and I’m here because of 2 questions :

  • I want to change the default format of 3d model in ply and not vtk
  • I want to unset compress option instead of doing it manually.

I don’t know anything about code and I wonder if it’s possible to do this.
Thanks a lot for your advice, it could save me a lot of time.

This is possible without you doing any coding, you just need to follow the instructions here: Script repository — 3D Slicer documentation in the section “Change default output file type for new nodes”.

For the compression option, add the line

defaultModelStorageNode.SetUseCompression(0) # change default to uncompressed

to your .slicerrc.py file right before the last line you just pasted in.

So, the 4 lines total which you will have added to the file will be

defaultModelStorageNode = slicer.vtkMRMLModelStorageNode()
defaultModelStorageNode.SetDefaultWriteFileExtension("ply") # change default to .ply
defaultModelStorageNode.SetUseCompression(0) # change default to uncompressed
slicer.mrmlScene.AddDefaultNode(defaultModelStorageNode)

These settings will take effect next time you open Slicer. So, if you add these lines to your .slicerrc.py file while you have Slicer open, you will still need to change the settings manually in that Slicer session.

1 Like

Thanks a lot. It works well!
Do you know if it’s also possible for nrrd and color table files?
Thanks

It looks like you could use exactly the analogous approach for color tables.

defaultColorTableStorageNode = slicer.vtkMRMLColorTableStorageNode()
defaultModelStorageNode.SetDefaultWriteFileExtension("txt") # looks like txt is the other option for color tables
slicer.mrmlScene.AddDefaultNode(defaultColorTableStorageNode)

For image files, it looks a little different:

defaultImageStorageNode = slicer.vtkMRMLVolumeArchetypeStorageNode()
defaultImageStorageNode.SetDefaultWriteFileExtension( 'nii.gz' ) # insert extension you want here 
slicer.mrmlScene.AddDefaultNode(defaultImageStorageNode)

I think this will likely work fine for the color tables. I’m less sure whether this will work for image volumes. If it doesn’t work, I would post a new discourse question on that topic to get suggestions from others. One consideration is that images are very likely to have been loaded from a particular format, and may remember that format rather than have that overridden by a default setting.

Thank you for your answer.
Maybe I was not clear but it was for changing the compression default for color table and image files.
Once again, thanks a lot

For the compression settings on each of these storage nodes, you can use the SetUseCompression() function. You can add the lines

# Insert this line before: slicer.mrmlScene.AddDefaultNode(defaultColorTableStorageNode)
defaultColortTableStorageNode.SetUseCompression(0) # 0 for no compression, 1 for compression

# Insert this line before: slicer.mrmlScene.AddDefaultNode(defaultImageStorageNode)
defaultImageStorageNode.SetUseCompression(0) # 0 for no compression, 1 for compression

I’m not sure which setting wins if the format/extension conflicts with the SetUseCompression() setting, but you can test and see. For example, if you specified the extension as ‘nii.gz’, indicating a compressed Nifti file, but set SetUseCompression(0), indicating not to compress it, I’m not sure whether the output would be compressed or not. Safest would be to make sure the two settings are compatible with each other.