# Document open/close events

**URL:** <https://discourse.mcneel.com/t/document-open-close-events/53329>\
**Category:** Grasshopper Developer\
**Tags:** event\_handling\
**Created:** [January 18, 2018, 4:13pm UTC](https://discourse.mcneel.com/t/document-open-close-events/53329 "2018-01-18T16:13:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dave\_stasiuk](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dave_stasiuk/32/507722_2.png) [@dave\_stasiuk](https://discourse.mcneel.com/u/dave_stasiuk)\
**Post date:** [January 18, 2018, 4:13pm UTC](https://discourse.mcneel.com/t/document-open-close-events/53329/1 "2018-01-18T16:13:33Z")

</div>

Is there any way to subscribe to events raised specifically on `GH_Document` open/close? `GH_Canvas.DocumentChanged` is useful, but it doesn’t tell me what happened to the old document, or where the new document came from. I have a singleton class tracking components that I’d like to clean up when a document is closed.

---

<div class="post-metadata">

**Author:** ![dave\_stasiuk](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dave_stasiuk/32/507722_2.png) [@dave\_stasiuk](https://discourse.mcneel.com/u/dave_stasiuk)\
**Post date:** [January 18, 2018, 4:55pm UTC](https://discourse.mcneel.com/t/document-open-close-events/53329/2 "2018-01-18T16:55:05Z")

</div>

Found what I need: `Grasshopper.Instances.DocumentServer.DocumentRemoved`

---

<div class="post-metadata">

**Author:** ![DavidRutten](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/davidrutten/32/755688_2.png) [@DavidRutten](https://discourse.mcneel.com/u/DavidRutten)\
**Post date:** [January 18, 2018, 4:57pm UTC](https://discourse.mcneel.com/t/document-open-close-events/53329/3 "2018-01-18T16:57:13Z")

</div>

There is no bottlenecking for events of all `GH_Document`s, but once you have a specific `GH_Document` you can subscribe to its events. Specifically `GH_Document.ContextChanged` may interest you.

---

<div class="post-metadata">

**Author:** ![dave\_stasiuk](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dave_stasiuk/32/507722_2.png) [@dave\_stasiuk](https://discourse.mcneel.com/u/dave_stasiuk)\
**Post date:** [January 18, 2018, 4:59pm UTC](https://discourse.mcneel.com/t/document-open-close-events/53329/4 "2018-01-18T16:59:15Z")

</div>

Aha. That’s good too. Thanks!
