I’d like to do a loop like for(i=0;i=10;i++);
Is there a component to do that?
I was looking at http://rhino.github.io/components/anemone/loopInput.html and found something called Anemone, but I don’t think I have that in Grasshopper or at least I can’t find it.
Most of plugins are on Foo4Rhino
If you’re new to Grasshopper lists and used to loops in other languages, you might be surprised at what can be done “the Grasshopper way”, without loops. What do you want to do?
I am new to GH and I’m used to languages like C++. How can you live without loops? Suppose I wanted to loop through a list of values and decide to jump out of the loop if a value exceeded a threshold? Just pulling that out of the air. I’d like to see examples of the “grasshopper way”.
In grasshopper the logic is more like make all the data then select/remove from it. Or make all data within a limit.
Thanks. I really appreciate both these examples. I have two questions about spider. The EvalSrf shows as “old”. What replaces it? The dashed lines have me curious. I’ve had some difficulty selecting the wire display never being sure of where to click to bring it up. Why did you make these lines dashed?
Thanks again. I learn a lot from examples.
I don’t know what happened to EvalSrf in Rhino 6?
As to the dashed lines, they indicate multiple branches in the data tree. I didn’t do anything, that’s the default behavior. So you can tell by looking at the wire if it’s a single item (one line), a list of items (double lines) or a tree with multiple branches (lists), the double dashed lines.
The ‘Maths | Script | EValuate’ component is another way to run a function on every item in a data tree, which can produce similar filtering effects.
boxes.gh (18.1 KB)
It’s not that I have anything against loops - I love Anemone. It’s just that Grasshopper has ways to do some things that don’t require loops. It effectively iterates through all items in a data tree (numbers, geometry, text or whatever), culling, dispatching, manipulating the data tree to make a new copy. The ‘Pr’ (Partial Results) output of MA (Mass Addition) is a subtle, different kind of example of this “touch all” way of thinking.
I don’t know what happened to EvalSrf in Rhino 6?
It just has extra U,V outputs.
Sorry to bother you reviving this topic. I´ve just wanted to share this paper about other looping alternatives. The authors compare three “non-Anemone” approaches for loops in GH: HoopSnake and Loop plug-ins, and GH-Python.
An old post but…what then is a good way to eg
I have a list of numbers, say 200 items normalised to 0-1 and I want to randomise each value slightly. Normally in looping you of course iterate through and apply random * scaling factor.
I am completely noob to Grasshopper but hopefully this helps someone else too
random_scale_2020Apr16a.gh (10.2 KB)
Thanks Joseph…thats great. I probably wasnt clear enough…the random scalar needs to be a applied to an existing list ie for each item in list apply random scalar. Assuming a list with eg
1,
2,
etc to 10 and a ®andom (s)calar of 1-1.1 it might be
index(0).val * rs = 1.065
index(1).val * rs = 2.033
and so on.
random_scale_2020Apr16b.gh (9.8 KB)
You can replace the Series component with an arbitrary list in a panel or from a file or whatever. This is REALLY BASIC stuff so you’ll have to try a little harder on your own…
Yeah thanks. The issue is that I have been scripting for many years (30) and the paradigms/vocab are the issue; its hard finding bridging resources that describe the lists like this…I have been on youtube so much my wife was wondering if she still had a husband :-).
What is shown implies iteration rather than explicit…will have to get use to that. What I mean is that its processing each item in the list separately which is normally a user directive…implicit processing.
I do use pure data/max msp a lot and whilst its very similar conceptually, it just lets you add your own scripting operators so the transition was very simple.
Appreciate your effort…hopefully there is someone else in my shoes who will also benefit
We all have struggled with data trees, they take some getting used to. Post your own code efforts with any future questions.
Thanks again Joseph…your attitude and help on this forum make it all the better.
Thank you, some would disagree… You found the right thread to address your question, that’s good! Keep up and enjoy. Cheers.