RunScript triggered with button suspends canvas

Hi everyone. I’m having trouble with executing a rhino command from a c# component.
I use a button as a trigger for rhino command execution in a c# script. But after button is pressed grasshopper canvas stops being responsible (it can’t be panned anymore) untill I press the button again. If a boolean toglle is used instead of a button everything works fine but you need to turn it off manually which is not very convinient either.

The script itself is rather simple.

private void RunScript(bool x, ref object A)
{
    if (x)
        {
          Rhino.RhinoApp.RunScript("-_Point", false);
        }
}

Using “Rhino Command” component from Lunchbox instead of c# produce the same result.
I thought maybe there’s a way to manually “update” GH_ButtonObject but couldn’t find any reference to it in API.

Test file is attached
rhino_command.gh (4.7 KB)

Using a second bool to make sure only call on false

  private void RunScript(bool x, ref object A)
  {

    if (x && !exe)
      exe = true;
    else if (!x && exe)
    {
      Rhino.RhinoApp.RunScript("-_Point", false);
      exe = false;
    }

  }

  // <Custom additional code> 

  bool exe = false;

  // </Custom additional code>

Thanks Will.
It works in terms of not freezing the canvas for sure. But this way Rhino for some reason awaits for me to click in the viewport to start showing point preview. Basically it requires double clicking.
I experiences the same behaviour when I connected a boolean toggle instead of a button and set it to false right after firing Rhino command in c# component.

apparently the same bug from 2013…

I had the same problem and i solve it using

Rhino.RhinoApp.SendKeystrokes("command",True)

Instead of using RunScript

1 Like