# Save Scenes in the same file

**URL:** <https://discourse.slicer.org/t/save-scenes-in-the-same-file/39582>\
**Category:** Support\
**Tags:** scene\
**Created:** [October 8, 2024, 11:49am UTC](https://discourse.slicer.org/t/save-scenes-in-the-same-file/39582 "2024-10-08T11:49:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SANTIAGO\_PENDON\_MING](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/santiago_pendon_ming/32/66060_2.png) [@SANTIAGO\_PENDON\_MING](https://discourse.slicer.org/u/SANTIAGO_PENDON_MING)\
**Post date:** [October 8, 2024, 11:49am UTC](https://discourse.slicer.org/t/save-scenes-in-the-same-file/39582/1 "2024-10-08T11:49:59Z")

</div>

Hi to everyone, me and my team are trying to save the scene in the same directory where we have saved the scene before.

```auto
    def saveScene(self):    
        """
        Saves the current MRML scene to the specified directory.
    
        This method performs the following actions:
        - Displays a message indicating that the scene is being saved.
        - Saves the MRML scene to the directory specified by `self.saveResults_path` under the '2_Slicer' subdirectory.

        """
        slicer.app.processEvents()
        scenePath = os.path.join(self.saveResults_path, '2_Slicer')
        # Verify if the path exist
        if os.path.exists(scenePath):
            # Remove the path
            shutil.rmtree(scenePath)
            # Create the path
            os.makedirs(scenePath)
        else:
            print(f'El directorio {scenePath} no existe.')
        # Save the scene:
        slicer.mrmlScene.SaveScene(scenePath)     

```

The problem is that `slicer.mrmlScene.SaveScene()` needs empty directories to save properly the data. In case the directory is not empty, the ` slicer.mrmlScene.SaveScene()` apparently removes the files but don’t save anything.  
To satisfy this requirement we tried to remove the files before saving but it does not work…

Literally we are trying to emulate the slicer interface when it asks if we want to override the files and clicks in ‘Yes to all’. First:

![Captura de pantalla 2024-10-08 134502](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/3/b3aeefa9a32dcad580cf5162b8851f62e0da7f7b.png)

, to check all the nodes and data. And second:

![Captura de pantalla 2024-10-08 134522](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/0/b09f9cb53c3a806b1b8c07a3e97bbd300cdf34ee.png)

, to override all the files needed.

My current Slicer version is : 5.7.0 -2024-10-05  
My OS version is: Windows 11

Thanks a lot 🙂

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [October 8, 2024, 11:58am UTC](https://discourse.slicer.org/t/save-scenes-in-the-same-file/39582/2 "2024-10-08T11:58:24Z")

</div>

Have you checked the `slicer.mrmlScene.Commit` function?

---

<div class="post-metadata">

**Author:** ![SANTIAGO\_PENDON\_MING](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/santiago_pendon_ming/32/66060_2.png) [@SANTIAGO\_PENDON\_MING](https://discourse.slicer.org/u/SANTIAGO_PENDON_MING)\
**Post date:** [October 8, 2024, 12:06pm UTC](https://discourse.slicer.org/t/save-scenes-in-the-same-file/39582/3 "2024-10-08T12:06:43Z")

</div>

Hi @cpinter, yes we tried it, but this function (as far as we know) only saves the scene, not all the data contained in the nodes ( for example, centerline curve JSON, volume nodes NRRD, segmentations…)

slicer.mrmlScene.Commit() needs any specific args to override and save all the data?

---

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [October 8, 2024, 2:05pm UTC](https://discourse.slicer.org/t/save-scenes-in-the-same-file/39582/4 "2024-10-08T14:05:20Z")

</div>

Hi all,

Indeed, we are facing problems with `slicer.mrmlScene.Commit`, `slicer.mrmlScene.SaveSceneToSlicerDataBundleDirectory`, and `slicer.mrmlScene.SaveScene()`.

It would be very useful to replicate the behavior of the Ctrl+S shortcut with an overwrite function. Otherwise, we always need to create a new directory to save scenes, unnecessarily increasing the number of files and memory usage.

Does anyone have any ideas on how to achieve this?
