I’ve been experiencing some issues with buttons in Grasshopper. Occasionally, pressing a button seems to freeze the canvas, making it impossible to interact with or click on anything until I force close and reopen the file. Because of this, I’ve resorted to using the standard Boolean Toggles instead, but they’re not ideal for my current workflow.
In this context, we’re using buttons for operations like:
Collecting geometry from Rhino (e.g., when geometry changes, the user needs to re-collect it).
Running custom components (using the button as a refresh trigger).
The main advantage of buttons is their temporary “True” state and the need to only click the mouse once, which would ideally act like a one-time refresh. However, once the component which is connected to a button finishes running, the button’s state goes back to “False,” and the data from the component gets wiped clean.
My questions are:
Is there a way to address the glitch where buttons freeze the canvas and prevent interaction?
Is there a method to make buttons retain data in the downstream components even after their state reverts to “False”?
Are there any recommended alternative solutions or approaches that achieve a similar “refresh” functionality without the need for Boolean Toggles?
Any insights or workarounds would be greatly appreciated!
My workaround in C# script components is to control the execution on the data using a boolean declared outside RunScript.
The button toggles the boolean when true and the at end of your script you flip it back.
This also applies to preserving the data. You can pass the result to a variable also declared outside the RunScript method. In python you can also use Sticky data to save anything and make it available in other Script instances
I have only used it for Rhino Commands / Resets, not for larger calculations. In case of larger calculations the group might be disabled again before it fulfilled the calculation.
Curious for @Felipe_Penagos 's solution, might be a better one.
Here is all that is to it.
The boolean that triggers the action is declared outside. And the data is preserved also by declaring the variable outside RunScript
Not sure if infallible but it works for me
private void RunScript(bool Activate, double Slider, ref object A)
{
if(Activate) Run = true;
if (Run){
dataToOutput = "I am available even if Activate is false\nThe slider value is " + Slider.ToString();
Run = false;
}
A = dataToOutput;
}
// <Custom additional code>
bool Run = false;
string dataToOutput = null;
// </Custom additional code>
}