Simulate a button click with python

Thank you @anon39580149. That’s exactly what I needed.

1 Like

The only thing that isn’t spectacular there is now you need to keep a timer on all the time.

2 Likes

i use enable/disable object for the timer
timer2.gh (6.1 KB)

2 Likes

:slight_smile: The script was added to this thread see:

You could simplify things by also scripting the GHPython component to update itself (i.e. instead of using a timer and plugins). This function should do it:

import Grasshopper as gh

def updateComponent(interval):
    
    """ Updates this component, similar to using a grasshopper timer """
    
    # Define callback action
    def callBack(e):
        ghenv.Component.ExpireSolution(False)
        
    # Get grasshopper document
    ghDoc = ghenv.Component.OnPingDocument()
    
    # Schedule this component to expire at interval
    ghDoc.ScheduleSolution(interval,gh.Kernel.GH_Document.GH_ScheduleDelegate(callBack))
6 Likes

Finally :smiley:

1 Like

I see that in other thread but i have 0 knowledge in scripting with grasshopper

:wink:

I wanted him to search the forum a little bit

That isn’t necessary, the code I posted above should work in the “normal” GHPython scripting component.

1 Like

Hi,

I don’t quite understand how to apply this script, or rather what its inputs and outputs are.
Do I connect my button component to it? What’s a reasonable interval to simulate a button click (or rather just the release -event)?
Where exactly in my Grasshopper solution do I insert this bit of GHPython?

Thank you in advance.

Here’s a quick example implementing it to trigger a dynamic counter loop (controlling the interval with a slider):


210918_DynamicCounter_GHPython_00.gh (4.1 KB)

1 Like

Hi Anders!

Thanks for the reply, especially in video form!
Super useful. While it’s not quite what I was looking for now, it’s something else that I have been looking for before!

With regards to the button click in Grasshopper without a double-trigger (press + release events) or freezing RCP:
I resolved to using a boolean toggle with a Metahopper component that resets it immediately back to False upon toggling it to True.
I find it unelegant only because it does not look like a button in the RCP, but at least it works with a single mouse-button press, like a button would.

2021-10-28_Metahopper Button Press

Hello everyone,

While reading your answer as I have a similar problem (coordination between components), I got an idea for another solution, which does not need a timer or script. It seems to work correctly and independently. What do you think?

2 Likes