Again about autosave

Hello! I just tried the Autosave utility from the sandbox. It’s very handy, but saving all scene in to a MRB file is too expensive.

How can I modify the AutoSave.py if i need to save only Segmentation.seg.nrrd file automatically?

I understand that I need to use myNode = getNode(“Segmentation”) script, but i have no idea how to paste it in AutoSave.py

Thank you for your assistance!

You should need to rewrite this code. Probably save only segmentation nodes would be much faster than making the mrb.

Yap, saving only Segmentation is much faster, but i didn’t know how to rewrite this code :sweat_smile:

Haha, yes, well it depends on how general purpose you want to be vs. hard-coding your use case.
Simplest would be something like this, just to save a series of segmentations you could browse through later if needed.

slicer.util.exportNode(slicer.modules.SegmentEditorWidget.parameterSetNode.GetSegmentationNode(), "/tmp/ausosave" + time.strftime("%Y%m%d-%H%M%S") + ".seg.nrrd")

But there are other things you may want, like only saving if there are changes, saving different segmentations with different names, etc.

You may also find the Export to file by pressing Ctrl+Shift+S key example in the script repository useful. It allows you to export the segmentation to a file on a keypress combination. You can modify it to save the segmentation node instead of a labelmap node, generate a new filename automatically (so that you don’t overwrite previous saves), etc.

@volkodavmyx What is the reason for autosave?

Were you able to make Slicer crash? If yes, then we want to know more about it (what operating system, how much memory you used, how big your data was, what operations caused trouble, etc.). We rather keep the software so robust that users don’t need to resort to autosave. If you find that sometimes you run out of memory then you can increase the swap/virtual memory size in your system settings (Windows/Linux) or make more disk space available (macOS).

If you just want to keep more undo states than the default then you can set it to a higher value by typing this into the Python console: slicer.util.getModuleWidget('SegmentEditor').editor.maximumNumberOfUndoStates=15 (it changes the number of undo states from the default 10 to 15). Just make sure you have enough memory to store the increased number of undo states.

1 Like