Rhino triggers events at first command run

My PlugIn MFis Wire uses events (e. g. ReplaceRhinoObject and AddRhinoObject) to detect if the user interacts with objects handled by the plug-in. When opening a document from within Rhino, events are triggered during the «Open» command which I can easily ignore. When opening a document by double-clicking in Windows Explorer however, a lot of events are triggered at the first command run. This causes my plug-in unnecessary object updates and unnecessarily activating a plug-in license. This is a bit annoying for the user. What can I do to ignore these events triggered by Rhino during the first command?

You can reproduce what I mean by opening the file:
MFis_Wire_Step_by_Step__5_Drawing_Bond_Wires_Part_2.3dm (1.5 MB)

Opening the file from explorer and calling the Command SampleCsEventWatcher will produce this output with many events:
open from Explorer.txt (14.8 KB)

Opening Rhino with an empty session, starting the event watcher and opening a file produces this result, which I can easily handle with my plug-in:
open from Rhino.txt (6.3 KB)

Any idea how to ignore the unwanted events triggered during the first command after opening a document from Windows Explorer?

Samuel

Hi @samuel.hartmann,

Does your plug-in load when Rhino loads or does it load on demand?

Does your plug-in add custom user data to documents?

– Dale

Hi Dale,

My plug-in loads at startup. I need this to listen for events for detecting when the user interacts with objects handled by my plug-in.

I am writing user data to the document by overriding PlugIn.ReadDocument and PlugIn.WriteDocument.

Samuel

Hi @samuel.hartmann,

In general, you shouldn’t configure your plug-in to load when Rhino starts. Rather, have your plug-in load on demand, which occurs when a user runs one of your registered commands. Also, if Rhino detects your plug-in’s custom user data, it will automatically load your plug-in (anyway) so it can read the data.

Perhaps when your plug-in load, you should create an Idle event handler. When your handler is called, then initialize your event watchers.

– Dale

Hi Dale,

I changed the load behaviour to load when needed. I don’t know why, but this solved the issue. It was not necessar to change something with my event handlers.

A drawback of this soultion is that there are some cases where the plug-in must be forced to load. An example is that I have a toolbar button that opens the plug-in’s document options page. This button did not work before the plug-in is loaded. So I created a dummy plug-in command LoadMFisWirePlugIn in order to force the plug-in to load before opening the document options page and added this command to the button action.

Another case is when the user copies objects with plug-in data into a document before the plug-in is loaded. In this case the plug-in does not detect the new objects and take the actions needed. The user has either to force the plug-in to start before or run a update command. Since this situation is very rare and the user can esily work around, I see this as acceptable.

Thank you Dale for providing your input here in this forum. It is always great to have somebody that knows what is going on under the hood of Rhino.

Samuel

Have your plug-in’s PlugIn.LoadTime property return PlugInLoadTime.WhenNeededOrOptionsDialog, not just PlugInLoadTime.WhenNeeded.

– Dale