How to reset or undo a specific step or def() by deleting the child folder created from it?

When designing a plug-in, the operator’s misoperation should be considered, so I want to add a reset method in the step. I want the step to run in a specific folder, so that the various Nodes generated by this step will be included in this child folder of the Subject hierarchy in Slicer, so I can complete the resetting this step by deleting this child folder. But how to write the code by python?

Or do U have some better suggestions to complete reset a special step or def()?

  • from google translator

设计插件时,应该考虑到操作者的误操作, 所以我在每个步骤都加了reset方法, 我想让每个步骤在一个特定的folder里运行,这样该步骤所生成的各种Nodes就会在这个child folder里面,这样通过删除这个folder就可以完成reset这一步骤的操作了, 可是具体怎么写代码呢?
或者还有更好的建议, 来完成reset a special step or def()?

@lassoan@Juicy@jamesobutler @jcfr @pieper

Undo infrastructure is implemented for segmentations, but currently undo is not enabled for other node types.

Slicer supports undoing all modification on all node types. You can give it a try by enabling it for the scene and for each specific node that you want to undo changes for:

myNode = getNode('F')
slicer.mrmlScene.SetUndoOn()
myNode.UndoEnabledOn()

# Now modify myNode, then run the next line to undo that change

slicer.mrmlScene.Undo()

The undo mechanism is not fully tested and optimized, that’s why it is not enabled by default, but if you enable it only for selected nodes then it should work fine.

1 Like