# Default format and compress

**URL:** <https://discourse.slicer.org/t/default-format-and-compress/21732>\
**Category:** Support\
**Created:** [February 1, 2022, 2:19pm UTC](https://discourse.slicer.org/t/default-format-and-compress/21732 "2022-02-01T14:19:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benoit](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Benoit](https://discourse.slicer.org/u/Benoit)\
**Post date:** [February 1, 2022, 2:19pm UTC](https://discourse.slicer.org/t/default-format-and-compress/21732/1 "2022-02-01T14:19:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [February 1, 2022, 4:50pm UTC](https://discourse.slicer.org/t/default-format-and-compress/21732/2 "2022-02-01T16:50:26Z")

</div>

This is possible without you doing any coding, you just need to follow the instructions here: [Script repository — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#change-default-output-file-type-for-new-nodes) in the section “Change default output file type for new nodes”.

For the compression option, add the line

```auto
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

```auto
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.

---

<div class="post-metadata">

**Author:** ![Benoit](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Benoit](https://discourse.slicer.org/u/Benoit)\
**Post date:** [February 11, 2022, 4:10pm UTC](https://discourse.slicer.org/t/default-format-and-compress/21732/3 "2022-02-11T16:10:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [February 11, 2022, 11:17pm UTC](https://discourse.slicer.org/t/default-format-and-compress/21732/4 "2022-02-11T23:17:49Z")

</div>

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

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Benoit](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Benoit](https://discourse.slicer.org/u/Benoit)\
**Post date:** [February 15, 2022, 10:10am UTC](https://discourse.slicer.org/t/default-format-and-compress/21732/5 "2022-02-15T10:10:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [February 15, 2022, 3:58pm UTC](https://discourse.slicer.org/t/default-format-and-compress/21732/6 "2022-02-15T15:58:56Z")

</div>

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

```auto
# 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.
