Return from RhinoApp.RunScript

Hi all.

I want to run/not run code based on the Result returned from a running a Rhino command. The docs state the return type of RunScript is a bool and doesn’t qualify it further.
https://developer.rhino3d.com/api/rhinocommon/rhino.rhinoapp/runscript

How should I do this?

private void ExecuteIntoGH()
{
    RhinoApp.RunScript("MyData_Into_Grashopper", true);
// if that was successful then open GH
    RhinoApp.RunScript("_Grasshopper", false);
}

Thank you.

So if this is running outside of a Command, the script will return immediately, and then your script will run, so you cannot rely on it for a “result”.

If you want things to execute synchronously, you will need them chained together in the same command if using RunScript. e.g.

RhinoApp.RunScript("_CommandToDoAThing _Grasshopper")

If you need there to be logic to determine if it should continue, you will likely need the first command to modify some kind of state in your plugin, and then check that state with another command before proceeding.

1 Like

check this:

you may also store and compare the NextRuntimeSerialNumber before and after the Runscript.

Rhino.DocObjects.RhinoObject NextRuntimeSerialNumber

Hi @Aurel_Axinte,

RhinoApp.RunScript returns a bool indicating whether or not Rhino ran your script. However, this is not an indication of whether or not the command completed successfully.

The RunCommand method of Rhino commands, classes that inherit from Commands.Command, return a Commands.Result value indicating if the command finished successfully, was canceled by the user, had some sort of unexpected failure, etc. This Result is determined by the command’s developer.

When scripting command, if you really want to know if the command was successful, then you’ll to watch for the Command.EndCommand event. Check the CommandEventArgs.CommandResult property.

If you do this a lot, then you might consider doing something like this fancy command.

TestRunScript.cs (2.8 KB)

– Dale

2 Likes

Personally, I would use the Script Syntax sticky dictionary to pass results between the scripts.

Cheers

DK

Thank you all for responding!

I’ve realised how much nuance there is around this and I’ll definitely need to do some proper event handling at some point.

For this really simple case (not opening Grasshopper is more a UX choice because what’s the point in seeing it if it hasn’t been properly populated) @jstevenson 's solution worked very nicely.

1 Like