Cancel opening of a document in RhinoCommon

Hello,

I have a situation in which I have to open a file which loads a Plug-in Im working with.

I need to check the document and see if its valid to open, if its not, I would like to abort the opening of the model.

Currently I’m able to cancel the loading of the Plug-in data, however the document with the host rhino geometry is still loaded

The solution I’m trying is to first generate a flag in ReadDocument override of my plug-in. And I register a event handler for Rhino OpenDocument event where I try to execute the following

RhinoDoc.ActiveDoc.Modified = false;

RhinoApp.RunScript("_-New _None", false);

This sometimes works, but sometimes it crashes Rhino.

There is a safe way to cancel the opening of a Rhino document that contains a Plugin content?

I think you should only modify the document in an event handler of RhinoApp.Idle, not in ReadDocument or OpenDocument.

Also, you need to think about what needs to happen when your plug-in is not loaded. Because in that case, the model will be loaded without your checking and possible interception. Also, why is it necessary to cancel opening a document in the first place? It seems you may confuse users?

It is not possible to prevent Rhino Events. You can however close the document without saving once you are done by opening a new document.

Possibly by using

RhinoApp.RunScript("-New N");