How to prevent canceling of RhinoApp().RunScript()


In my C++ plugin I am loading several RhinoScript procedures using RhinoApp().RunScript() at startup, for example I pass the following as a string to RhinoApp().RunScript():

-_RunScript (    
    Sub MyHelloWorld()
        Rhino.Print "Hello World!"
    End Sub

Afterwards I call these procedures from my plugin commands like this:

bool result = RhinoApp().RunScript(L"-_RunScript ( MyHelloWorld ))

This works perfectly well, I suppose this is also roughly the way the script compiler in Rhino 4 worked. There is just one thing I would like to achieve:

My question

How is it possible to prevent RhinoApp().RunScript being cancelled by the user using ESC?

What is your concern with the user canceling your script?

If the user cancels the script, it might leave the data in the Rhino document in an undefined state. Therefore I would like to prevent canceling.

Does this help?

Hi Dale, this certainly helps, at least it allows me to warn the user. I suspect blocking the ESC key might be possible using some C++ code, or is there absolutely no way?

Maybe. But anything else would require a modification to RhinoScript. Is it possible to re-write your script in C++?

Rewriting in C++ is not an option, however it would be very helpful if it were possible to create a snapshot of the Rhino-document at the beginning of the script, and roll back to it in OnCancelScript.

RhinoScript is document-centric. If you want to make stuff in memory and add it to Rhino all at one time, then you might want to look at Rhino.Python.