How to trigger recompute of definition with a button in Rhino

Hello all,

is there a chance to trigger specific grasshopper components via a Rhino Button? I tried the following:

  • create a button that switches the sticky from true to false and vice-versa

  • set the sticky variable in GH

  • press the button in Rhino

  • the sticky variable actually changes in the definition, but You have to hit the “update”- Button, which makes the whole procedure useless…

Another thing I found that could possibly be useful here was
but how can I trigger that from Rhino?

Has anyone an idea how to solve this?
Thank You in advance!

If hitting the update button is the problem…
What about using Grasshopper’s remote control panel?


It’ll create a UI panel for you :slight_smile:

Maybe you can use Metahopper’s Expire Object component.
It has a boolean input that you can link to your Python code output.

If you recompute the first component of your script it should be the same as hitting F5.

Edit : does not work :frowning:

hi cameron,

I have it in the RCP, but I have to switch between Layers, Properties, DocUserText… and tried to avoid another switch to the RCP

This seems to work.

! _-RunPythonScript (
import Grasshopper


From Rhino- Precompute grasshopper python script - #6 by JoshD

1 Like

Oh great that works fine!
It’s recomputing the whole definition, but that’s ok for me.

You could track their instance GUIDs and do something like this (i.e. you will want to expire components with specific instance GUIDs):

And if you’re running this from a Rhino button, you can replace ghenv.Component.OnPingDocument().Objects with Grasshopper.Instances.ActiveCanvas.Document.Objects.

Edit: You could also target components with specific names, substrings etc. if working with GUIDs aren’t appropriate.

1 Like

Hello Anders,

thanks a lot, I will try.

Finally it works as expected!
The script inside the button looks like:

!_-RunPythonScript (
import Grasshopper
for obj in Grasshopper.Instances.ActiveCanvas.Document.Objects:
    if obj.NickName == "recompute":
        obj.ExpireSolution(True) )

Pressing this button makes the object “recompute” to load again’; the rest of the definition does nothing.

Thank You Anders!

1 Like