Trying to figure out a way to trigger four double click toggle switches with one click

Good evening everyone I have a question. I am working on a script that generates some drawings. Basically the way it works is that I have four toggle switches and grasshopper. They each have to be toggled on and then off in a specific sequence for this to work.
image
My question for you is that is there a way that I could write a add-on to this expression that would toggle each one on and off with a specific amount of time delay between each click? In other words I’d like to have one button that would start a sequence where each toggle is clicked on, and then about three seconds delay, and then clicked off and then it repeats through the other toggle switches. Has anyone ever set something up with a time delay like this?

maybe like this:


timer.gh (14.2 KB)

You can script just about anything. Here’s a quick example of sequentially flipping a list of named toggles over time at an interval delay:


210407_FlipTogglesOverTime_00.gh (4.7 KB)

6 Likes

This is cool!

1 Like

Good morning AndersDeleuran, thank you so very much for taking the time to answer my question. I very much appreciate it. I am new to the Grasshopper profession and it never ceases to amazing me not only how useful this tool is but how helpful this forum is to people learning it. I am looking at your script and it’s amazing. Question, is it possible to set this up so that each switch is toggled on and off in squence? In other words the “Food” toggle is flipped to true, wait a set number of seconds, then flipped to false, then on to the next toggle? Thank you so much for your time and helping me learn.
Gregory

There’s probably a simpler logic, but one can track the previous toggle and then flip that back as well:


210407_FlipTogglesOverTime_01.gh (5.3 KB)

Maybe you can post a larger example of your pipeline/dataflow. It’s usually better to solve such sequential concerns (i.e. first this should be computed, then this, then that etc.) by the directed acyclic graph (DAG) dataflow of the Grasshopper pipeline itself (i.e. by organising and structuring your definition dataflow such that it resembles the logic you have in your head).

1 Like

I’ve recently found out that it’s often performance-wise better to use ClearData(), instead of ExpireSolution(). It sets the current, active object to blank, informs the active document that it has expired, but has a less destructive expiration, because it doesn’t expire all objects that depend on the active one. It thus depends on the case, whether you can use it or not. Here it works fine!

1 Like

Ah yes, I completely forgot to expire. Which in this case causes the “object expired during solution” warning. I forget, but I’m pretty sure I solved this a while back for cases such as these. Anywho, that’s a really interesting find, thanks for that :slight_smile:

1 Like

Hey @AndersDeleuran !

I was looking through the forum and found this post and since then I’m trying to make some changes in the script (just for the sake of practice)

I’m new to scripting in Grasshopper and I’m wondering if is possible to create a counter or a iteration number to this process. For example: Iterate only 3 times the “false, true, false” or 4 times “false, true, false, true”. I tryed to implement a for loop between the if Run but it didn’t make any difference :rofl:. any thoughts on how I could create this feature?

Bests

Hello again,
Thank you so much for your time. I looked at your expression and I thought that was exactly what I needed. I tired patching it into my expression and I hit a snag. I am working with a team on this and I wrongly assumed my switches were toggles, they are not. They are actually VALUE Lists. Please see my cropped expression. Gregs Buttons.gh (4.0 KB)

1 Like

Since you have just two states “true and false” in the value list, you can’t just change to toggle?

Hello Leonardo Gindri, thank you responding. This is an odd situation. If I make a new toggle switch and put it in place of the value list, then manually double click the button, the function works. But if connect AndersDeleuran 's script to the toggle, and activate it, the toggle switch functions, but the connected expression does not work. So bizarre.

Question, I was playing with your script out of curiosity and I noticed something, if I layout some toggle switches, lablel them to work with the script, then activate the script with panels attached to the toggles, the input for the panels doesn’t change. Look here:


Am I doing something wrong?

Yes that’s because I forgot to expire the toggles after setting their values (as noted above). Here’s a quick implementation with that included. As noted, this will cause a warning the first time you run the script though (check the “Do not show this message again” box and click Close):


210408_FlipTogglesOverTime_00.gh (6.5 KB)

Also, again, I’d really advice that you solve this by proper DAG dataflow, instead of timer-based non-DAG dataflow shenanigans (fun as it is). That is, separate your definition into four sequential stages, and have each stage trigger the next in a linear pipeline. Like so ImportRebuildBakeExport.

Sure, you can manage this with persistent variables as well. Here’s a quick go at implementing a counter that increments at each iteration (note that this definition raises a warning on first run, see above):


210408_FlipTogglesOverTime_01.gh (5.3 KB)

:wink:

Pay attention :wink:

For me it causes the Grasshopper breakpoint warning on each expiration. Constantly!

Even if you check the “Do not show this message again” box? I don’t use Mac, so that might be a factor too. Anywho, as I said I recall having solved a similar situation, but can’t remember how (think it was scheduling the expiration of the toggles as well). And again, I would really recommend solving these cases by linear dataflow instead of inherently hacky dynamic solutions.

Edit: Here’s a version that uses a trigger and ExpireSolution(True) on the toggles. Which seems to run with no issues/warnings on my Rhino7 PC version:

210408_FlipTogglesOverTime_02.gh (8.1 KB)

This seems to have fixed it! :slight_smile:

I haven’t checked that.