True/False Looping based on a given number of cycle

Hi Guys, I’ve struggling quite abit with GHpython lately. I am a Mechanical Engineer and a total noob at python programming. (only familiar with some C++ knowledge I have learnt in school)

Here’s my story:
I have always wanted to automate screen capture process and I have created a workflow shown below:

It is basically to assign a color to the Brep and take a Rhino viewport screenshot.
Hence, the color can only be done one at a time.

Here’s the problem
Imagine now I have 100 colors needed to be done, I will have to repeat the process 100 times and it is very prone to human copy & paste error. Therefore, I begin to look into automation. The logic flow is as shown below:

Browsing through the internet, I came across a script that runs in Python without any Trigger, which is very good because there is no need to manually reset the timer.

Due to my lack of knowledge in python, I couldn’t figure out how to properly use a For loop to active True/False condition based on a specific list-length/cycle given.
I have attached my script here and I hope anyone out there can help me on this (just to make this True/False toggle behave correctly will be good enough). Greatly appreciate your help.

True-False-Cycle.gh (5.1 KB)

Thanks in advance!
Chua Ching Hong

Hi Chua

Maybe I don’t understand the issue, you want to just cycle 5 times? Or you want to cycle a 100 times but flip a switch every 5 times.

The sliders have an animate option that captures screen grabs for very integer.

But maybe I’m not understanding what you need

1 Like

Hi there. Thanks for your reply.
Sorry for the confusion.

What I need is to have a loop that cycles X number of times depending on the list length given. For this case I have 5 RGB values, I will need to have 5 cycles of True to False in order to act as switches to trigger the capturing of viewport.

The issue I noticed is that using the For loop, computation is done from start to end which takes about 5second and returns
True
False
True
False
True
False
True
False
True
False
And only 1 image was written

What I need is:
True (write image 1)
False
True (write image 2)
False
True (write image 3)
False
True (write image 4)
False
True (write image 5)
False

PS: I am currently using a trigger with data recorder as temporary solution. Using the trigger (with series and modules/2 to create 101010… pulse and then convert to the True False switch) it works, just that in future I am considering running this automation I’m server. Hence, they might be nobody to press the Trigger and Reseta.

Hope this is clear to you :slight_smile:

Thanks
Chua

Unless Python is really needed somewhere. Normally a Series is created to create a list.

This shows different ways to do this. The first is the most popular way:

There are also ways to create a alternating list of true false if needed.

Hi Scott, thanks for the feedback.
I need python because I found the script which was done by AndersDeleuran so useful that it uses GH timer to create an internal Trigger.
Just that I have no idea how to proceed further to create looping.

I am currently using Trigger and Data recorder to create the live True False switches. It works but it’s only temporary solution.

The key is to use the GHPython compone with list access. Here is the main guide on this:

So once the list is input, then let Python roll over it:

"""Grasshopper Script"""
lst = []
for i in range(len(x)):
   lst.append(x[i])

a=lst

image

Is the final aim of the script to take screen grabs? If so why would the animate option not work? I believe it was designed for this exact type of thing. A Scott says I don’t see the need for python.

If you post your full script, screen capture part included might be easier to understand.

Animate would work, although there are simpler ways. Here are two ways, testing a channel against a value is the top one. Or the bottom one the classic series trick that will send a series of numbers or true false down the pipe:

@chuachinghong - It is important to note that Grasshopper itself is always looping itself through these lists.

This is a way to get a true alternating pattern of bools:

Or checking for Null in the list:

Hi there
Many thanks for the reply.
I have posted my script here. The images will be generate per second and write into the folder C:\Temp

As you can see, what I want is to have a single button/click for the screen capturing.
However, the problem you can see here is that user need to manually pause the Scheduled Update to start/stop the image generation. In addition, he will need to reset the count in the data recorder after the job is done.

As mentioned by Scott, Grasshopper itself is always looping through the entire list. Hence I think this is the reason why a string of:
True
False
True
False

will not work on the Ladybug Capture View module. Whereas if I send a live 'Pulse" that generate:

True then False
delay 1 sec
True then False
delay 1 sec

Then it will work.

What I hope to output from GHpython with For loop is:

Step 1: Detect how many list are there to determine the cycles needed
Step 2: Use a for loop to generate the snapshot function per cycle

The behavior of one cycle snapshot function I am guessing should be based on this sequence:

  • Show True
  • Show False
  • Pause for 1sec
  • Clear memory

Next cycle comes in…

Automation Render Forum.gh (21.8 KB)

I am just curious if GHpython is able to create the live ‘Pulse’ to simulate Trigger. If this is not possible, then I will give up exploring.

Greatly appreciate your help on this :slight_smile:

The animation panel in the slider is a great option. But the lady bug has got more controls. Disadvantage is it requires boolean toggle to trigger the image export…

Hi Chua

It seems to me using python over complicates things, the script you have with a timer works fine.

You just need to leave the capture component always on “true” and as each time an input changes it will just take another picture.

And add a test to see if the counter exceeds the amount of values on the list and flip to “false”

Automation Render Forum_NL.gh (25.0 KB)

If you have a python component it will still loop through the whole thing and output a list of trues and false in one go, so unless you hook it to a timer I don’t think it doesn’t what you want it to.

But again maybe I’m missing something.

1 Like

Hi NL

Omg! Your suggestion will complete the ‘loop’ I was wishing for.
I just got to find a way to ‘link’ start, pause and reset to some element from Human UI. That’s my ultimate goal basically.

But ya, your solution is very good! What a smart way to use Stream Filter man. Appreciate it :slight_smile:

Yes! The GHpython doesn’t seemed like the ‘real’ python. If I set to sleep/delay, grasshopper will hang. Ok for now I will forgo using GHpython.

Thanks again
Chua