Rhino window close event

Dear all,

I’d like to run a dialog form when Rhino is closed.
Currently I’m using the Rhino.RhinoApp.Closing event.
However, this takes a couple of seconds to fire after the Rhino window has been closed.

I notice Grasshoppers ‘You have unsaved documents’ dialog popping up instantaneously after the Rhino window disappears.

I tried using the Rhino.UI.RhinoEtoApp.MainWindow.Closing event but that does not seem to fire. Is there any other event that I could use?

Any help would be greatly appreciated!

Grasshopper starts to perform cleanup and last-ditch saving UI in response to a call placed to OnShutdown method of the plugin class.

    protected override void OnShutdown()
    {
      try { Grasshopper.Plugin.GH_PluginUtil.SaveSettings(); }
      finally { }

      try { Grasshopper.Plugin.GH_PluginUtil.UnloadGrasshopper(); }
      finally { }
    }

So I would need to override the OnShutdown method like so

protected override void OnShutdown()
{
  base.OnShutdown();
  // Show my dialog here...
  // Or maybe fire an event that triggers my dialog from somewhere else?
}

But where do I do this override, wouldn’t that mean I’d have to subclass the whole Grasshopper plugin? This seems a little over the top for the task at hand…

OK, I just found out that by plugin class you mean Rhino.PlugIns.PlugIn.
However, it still is not clear to me how I could implement my stuff there…

Are you making your own Rhino plugin? If not, then this doesn’t help you.

No I’m just making a plugin for Grasshopper…

The strange thing is that I can’t seem to get it to work with the Rhino.UI.RhinoEtoApp.MainWindow.Closing event which I suspect to be the one that fires when the Rhino window closes. But it doesn’t…

Closing and Hiding aren’t the same thing though.

Agreed, but does that mean that the Rhino window is only hidden during shutdown and then closed after a few seconds?
So I should go for some sort of hiding event that occurs during shutdown?

Just to get this clear: is the rhino window an Eto.Forms form or a System.Windows.Forms form?
I can get an eto form using

Rhino.UI.RhinoEtoApp.MainWindow

but this returns null

IntPtr handle = Rhino.RhinoApp.MainWindowHandle();
Control mainWindow = Control.FromHandle(handle);

I don’t know right now, not too long ago it was neither. Rhino is a C++ project and we were using MFC for the UI. The actual window was wrapped in specialist implementations of winforms to make it look as though there was a recognisable Form there.

Now however there is a bigger separation between the core and the UI, so maybe in recent versions of Rhino6 the main window is really an Eto form. I don’t know. @curtisw?

The Rhino main form is currently neither an Eto Form or Windows Form. On Windows I believe it is created via MFC, whereas on macOS, it is created via a NSWindowController in a xib file.

We have wrappers so you can use these as a parent window for Eto Forms or Windows Forms as you have noticed (e.g. RhinoEtoApp.MainWindow and RhinoApp.MainWindow), but trying to use things like the closing event (or any event) of those wrappers probably won’t work.

The best bet is to use the overrides in the plugin, or the static events such as RhinoApp.Closing, etc as mentioned.

Hope this helps!
Curtis.

OK, thanks for the info @curtisw!

@DavidRutten would it be possible for you to modify Grasshopper’s OnShutdown method to also fire an event (e.g. GrasshopperClosing) after calling SaveSettings that I could listen to?
Because at the moment I don’t see a way that I could go to make it work like I would like to have it…

Hi, I was wondering if you know any way of accessing the Minimize and Maximize events of the Rhino Main Window? Thanks.