# Looping solution by layer list count

Hi,

I’m trying to make a recursive solution based on a layerlist content. Since each layer could have many objects, I’m trying to fire them using a timer for each entity and record them. After counter for each layer achives its lengh, increase +1 using anemone, and staring over and over, until it reaches the lengh of layer list total count.
I’m trying to accomplish this because I don’t want to duplicate the solution fifith times or more for each layer.

It’s not working on anemone adding my initial list (always 0) to the next (1, 2, 3… lengh total).
Also the timer stop working after the first fire. Is it possible to make it again for each time?

Anyone would like to help? Thank you!

loopLayerCount.3dm (34.5 KB)
loopLayerCount.gh (16.1 KB)

Honestly I do not understand anything you want to do.

Getting some Rhino geometry?And than?

Sorry if it wasn’t clear @Baris.

I want to get geometry from rhino through my layer list. But I can’t do this getting all of them at the same time, I need to get one by one using a trigger timer. So, after getting the content of layer A, I move to layer B and so on…

That is just a simplified example. My major concern is how to perform a recursive solution just by adding a counter. I know it not possible to to using only grasshopper, so I choose Anemone, but it’s not working.

no worry,
but it is still not clear to me.
Maybe you can elaborate what you want to do after getting the geometry in GH(which is easy doable for example with human or elefront-without recursion)

Get the layer content isn’t the problem @Baris, the main issue is how to perform a layername selection on by one. Why? Let me give you a better example, I want to subdivide each polyline using the definition attached. Since the subdivion work using a surface, it only could be done one after another. So that’s the reason I’ve take a timer. So my listitem component can take each number by another from by layerlist content lengh.
If I dont do this, this definition will never work. OR I should to copy the entire definition for each layer. If I have 50 layers, imagine how this document would be crowd and not efficienty.

loopLayerCount2.3dm (39.2 KB)
loopLayerCount2.gh (45.3 KB)

layername selection?
Sorry I still do not understand.Probably its just to late and you need to wait till someone else can have a look at this.

I’m currently reading through your script and can’t quite understand what is the purpose.
From what I see, the issue is having a loop inside a loop, rather than smart use of trees.

Based on what I can execute, it is a packing algorithm of some sort, so I don’t understand why each surface can’t be treated as it’s own object, run with a flat list and then using partition list to make it back into the original tree shape?

@christopher.ho

The way of the subdivision logic was designed it just accept a single surface. If I have a set of polylines, it doesn’t work. So I need to figure out a way of recurse my ListItem component to retrieve my list of indexes one by one.

It is not a matter of smart use of trees, because grasshopper doesn’t allow recursion only with vanilla grasshopper, you need some scripting for this.

This sounds like a something you would avoid in the most cases with data management.

Here is my take on it:
Exiting without outputting the final surface in the inner loop
The inner loop needs to be redone, but it will atleast calculate everything.
loopLayerCount2v2.gh (70.2 KB)

1 Like

Great @christopher.ho, thank you!!

When you flat all layers and fire them without giving time to function properly subdivide the polyline you risk yourself having wrong subdivisions as you see in your take.

I imagine the best way to solve this “breath time” it is to “read” one layer by another and firing each polyline using a timer. So if I have 5 polylines in first layer, and my timer is set to 500 miliseconds, the definition has time to process each one without errors. When timer reacher the limite (list lengh), it move to next layer and so on…

Why does it take time to subdivide? I read it in all at once.
The problem is the exit condition of the inner loop is not right and the merge I used to join was done wrong.

Oh yes, totally! But in my case I need to give a timer for my definition “works properly”. I can’t handle my input as individual unfortunately, it need to be in parts.

I tried out to solve this in a hundre ways but I really couldn’t. It’s super trick.

Is there any particular way the blocks need to be stacked?

Not actually. They only need to be in the same branch (layer) as the beginning. For example, the polylines of layer A as result into 9 subdivision, so these 9 polyline as to be stacked in the same branch (layer correspondent).

Actually seems you’ve done!

Much easier to loop through a flat list, hence I flattened it first and then regrouped it based on the initial tree. It was just a mistake with the maximum loop iteration and adding the result to the wrong output.

1 Like

@christopher.ho Thank you so much! A very clean and elegant solution, i’m amazed!