Double loop

Hi all,

In short, i am trying to figure out how to handle a double loop (minor and major) using ‘anemone’ plug-in. The problem is, the amount of reps of the major loop. I need it to do the loop every time once the minor loop is done, and not every time data is passing through minor loop.

Although i can’t upload the script, I came up with an alternative concept:
Lets say i have a set of randomly placed points and couple of circles, as a minor loop i need each circle to identify points within his area and connect them one by one, and as major loop i just need a value that will be used as index for circle selection in order to perform that task for all of them, one by one (i=0 … points connected => i = 1 … points connected => i = 2 …).
Note:
Simultaneous computing is not an option, only one by one

Within my knowledge (few years of grasshopper and almost 0 at coding) i came up with 2 dummy solutions:

  1. Find the worst case (larger amount of points inside) and use the outcome value (((amount of points) - 1) * number of circles) as amount of reps that should be enough for major loop to include all reps of minor loops.
  2. Combination of ‘Trigger’, ‘Recorder’ and ‘List length’ with a time that is ok for the worst case so that all others are gonna be completed until index change.

The problem with both solutions is efficiency, in terms of computational load and time because the amount of points is somewhere between 100-900 …

I am refuse to believe that there is no ‘simple’ solution for something like that, any solutions/ ideas/ references to thread/ attention :smiling_face_with_tear: are highly appreciated!

Too bad for you! I’ve written nested Anemone loops a few times and they work fine. Demonstrated ten days ago here:

Full size:

3 Likes

this is just a very poor example of what I have understood you might want to do…

the point I wanted to raise is that in many cases you don’t really need to pass geometries inside the loops, but you can just handle their indexes (as you have pointed out yourself already)

but in those cases you need to have something that “triggers” the loop components in such a way they understand when it’s time to go and when it’s time to let something else do its thing before going

in this case, two circles are fixed on XY plane, and there are 2 nested loops:

  1. first loop just controls the seed of random populated points (so it handles ints)
  2. second loop just goes through the index of all the points which happen to be inside circles (so it handles ints again)

→ clicking A triggers loop_1 to start, its counter feeds tp the random point seed and generates a set of random points
→ as those points are generated, they trigger loop 2 to start because new data is input in its D0
→ meanwhile loop_1 is “listening” for an input on its D0 to go to its next iteration, but nothing arrives there because loop_2 is set to “Last & Record” so it will output data only after having done all the iterations it is instructed to do
→ so loop_2 goes through all its iterations silently while loop_1 waits… and when loop_2 outputs its final result, it goes to D0 of loop_1 which triggers a new iteration of loop_1

maybe this is a bit “intricate”, but hopefully might be of help :slight_smile:


nested_loops_ints.gh (19.2 KB)

1 Like

Good time of day to all and thank you for your responses!

@inno

maybe this is a bit “intricate”, but hopefully might be of help

Not at all, actually that was exactly what i was looking for! Because essentially the whole point was to achieve:

something that “triggers” the loop components in such a way they understand when it’s time to go and when it’s time to let something else do its thing before going

I have tried out almost everything i knew, with the biggest estimations from ‘Key/Value Search’ but even this component triggered the loop … ALL i had to do is just to set the minor ‘Loop End’ to ‘Output last’ -_-

P.S. It seems like my description was too “abstract” because what i tried to describe was:
Example.gh (18.5 KB)
:sweat_smile:

@Joseph_Oster
It’s funny that by pure chance I opened that thread while skimming; although I found the problem and its solution, at the first opportunity I will definitely study the content of your algorithm better!

1 Like