Determine when a Layout is Created or Deleted

I’m making a plugin that (in part) keeps track of detail views, and I need to know when the user deletes a detail view so that the plugin’s state can change accordingly and I can register an appropriate undo action, so if the detail view is restored the state can be restored as well. However, I’m having some issues with layouts and their events.

Because deleting a layout cannot be undone, I need to know if a detail view was deleted directly or by deleting the layout - if it’s the former, register an undo action, but if it’s the latter, don’t register the action. DeleteRhinoObject registers both actions as the same, and the layout itself is not detected by the event, so distinguishing between the two different ways of deleting a detail view seems impossible. Any advice?

TL;DR: I’m wondering if there is some way to detect if a layout was deleted, or if a detail view was deleted directly by the user or by deleting the host layout.

Hello @Cole_Howell1,

Based on no research whatsoever other than the floating thoughts on the top of my dome and a hunch. I don’t think you’ll find an event to tell you specifically what you need to know.

Likely you’ll want to track various events in Rhino and deduce what has happened yourself.

Dale has made a snazzy event watcher → rhino-developer-samples/rhinocommon/cs/SampleCsEventWatcher at 8 · mcneel/rhino-developer-samples · GitHub

I’d fire that up, try some of the scenarios you mentioned and see if you can determine what happened by the sequence of events, if not, I’ll try and think of something else :slight_smile:

Thank you for the response Callum. I found that the event PurgeRhinoObject fires when a detail view is deleted via deleting the parent layout, so watching that solves my current problem. I’ll leave the topic open for now as knowing when a layout is deleted would still be useful.

Hi @Cole_Howell1,

Subscribe to the RhinoView.Destroy event.

– Dale

1 Like