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.
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.
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.
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:
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:
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…
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.
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
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.