# Scene initialization and modified state

**URL:** <https://discourse.slicer.org/t/scene-initialization-and-modified-state/10152>\
**Category:** Development\
**Created:** [February 7, 2020, 7:12am UTC](https://discourse.slicer.org/t/scene-initialization-and-modified-state/10152 "2020-02-07T07:12:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rprueckl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rprueckl/32/4240_2.png) [@rprueckl](https://discourse.slicer.org/u/rprueckl)\
**Post date:** [February 7, 2020, 7:12am UTC](https://discourse.slicer.org/t/scene-initialization-and-modified-state/10152/1 "2020-02-07T07:12:28Z")

</div>

In my application, at startup or after a scene change, I do some initialization tasks for some of my modules. After this is finished, the scene of course is always marked as modified and when I try to close the application, it asks me whether I want to save the scene. For the user, however, the scene is empty and untouched. Is there a way to reset the modified state of all the nodes in the scene (including storage nodes) without actually saving the scene?

---

<div class="post-metadata">

**Author:** ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)\
**Post date:** [February 7, 2020, 9:34am UTC](https://discourse.slicer.org/t/scene-initialization-and-modified-state/10152/2 "2020-02-07T09:34:59Z")

</div>

You can close the scence(shortcut:ctrl+w) in the “file” of the manu but not close the slicer app .

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 7, 2020, 2:10pm UTC](https://discourse.slicer.org/t/scene-initialization-and-modified-state/10152/3 "2020-02-07T14:10:34Z")

</div>

You can iterate through all storage nodes and call `storageNode.GetStoredTime().Modified()` to indicate that changes has been already stored, so there is no need to save the node. I don’t think `StoredTime` attribute of `vtkMRMLScene` is exposed publicly, so you may need to call `Commit` method to write the scene to some dummy file (if it does not work then we can add a method to allow marking the scene object as “stored”).

---

<div class="post-metadata">

**Author:** ![rprueckl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rprueckl/32/4240_2.png) [@rprueckl](https://discourse.slicer.org/u/rprueckl)\
**Post date:** [February 7, 2020, 9:50pm UTC](https://discourse.slicer.org/t/scene-initialization-and-modified-state/10152/4 "2020-02-07T21:50:54Z")

</div>

Thanks for the hint. I managed to achieve what I need in this way:

```auto
// create default storage nodes for all storables
std::vector<vtkMRMLNode*> storableNodes;
mrmlScene->GetNodesByClass("vtkMRMLStorableNode", storableNodes);
for (auto&& storableNode : storableNodes)
{
  vtkMRMLStorableNode::SafeDownCast(storableNode)->AddDefaultStorageNode();
}

// set the stored time of all storage nodes to now
std::vector<vtkMRMLNode*> storageNodes;
qSlicerApplication::application()->mrmlScene()->GetNodesByClass("vtkMRMLStorageNode", storageNodes);
for (auto&& storageNode : storageNodes)
{
  vtkMRMLStorageNode::SafeDownCast(storageNode)->GetStoredTimePtr()->Modified();
}

// set stored time of scene to now
mrmlScene->GetStoredTimePtr()->Modified();

```

In my fork, I added:

```auto
//------------------------------------------------------------------------------
vtkTimeStamp vtkMRMLStorageNode::GetStoredTime()
{
  return *this->StoredTime;
}

//------------------------------------------------------------------------------
// Added method that returns pointer to StoredTime
vtkTimeStamp* vtkMRMLStorageNode::GetStoredTimePtr()
{
  return this->StoredTime;
}

```

and

```auto
//-----------------------------------------------------------------------------
vtkTimeStamp* vtkMRMLScene::GetStoredTimePtr()
{
  return &this->StoredTime;
}

```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 8, 2020, 1:10am UTC](https://discourse.slicer.org/t/scene-initialization-and-modified-state/10152/5 "2020-02-08T01:10:28Z")

</div>

Thanks for sharing. FYI, in custom applications we usually override the entire save dialog.

---

<div class="post-metadata">

**Author:** ![rprueckl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rprueckl/32/4240_2.png) [@rprueckl](https://discourse.slicer.org/u/rprueckl)\
**Post date:** [February 9, 2020, 12:54pm UTC](https://discourse.slicer.org/t/scene-initialization-and-modified-state/10152/6 "2020-02-09T12:54:42Z")

</div>

Thank you, yes, I alredy did this, however I still use

```auto
if (scene->GetStorableNodesModifiedSinceRead() || scene->GetModifiedSinceRead())

```

for determining whether there were changes to the scene.
