ItemAtIndex for different lists and levels

Hello everyone,

I’m having a hard time setting up a way to get specific items from nested lists of elements by using another list of indices, when the two lists have different levels. Is it possible to achieve what is shown here in the blue and green colors?

Ideally the number of Level 4 lists from the dictionary node can vary, but will always match the amount of Level 2 lists form the index lists. The number of indices (only one per list in this example) can also vary. I need to keep the same structure and sublists from the list as shown, so it seems like flattening is not one of my options here?

Cheers

They’re two different outcomes, so I don’t really understand what you’re looking for. Can you show us the outcome you want? Are you looking for the @L3 lists in green or the @L1 items in blue? As long as you’re matching the structure there should be a solution. Sometimes a solution requires you to duplicate values so that you do match the structure.

1 Like

Hi Nick, thanks for your reply. Apologies, my example should have been more clear. Hope this helps:

This is going to require us to look at how the GetItemAtIndex node anticipates and handles input structure. The list input obviously requires a list structure and the index input is expecting an integer. Both inputs can have additional structure beyond the basic format, but that doesn’t change how the node handles their relationship.


In the first example, you can see that index structure doesn’t change where the node is looking for the index within the list structure, only the structure it returns.

Even with that additional level of data in the list structure, the node treats the top level list as the input. This is obviously where list levels can change what level the node iterates over, but list levels can’t change where the index is looking because the node itself doesn’t use structure to identify location (the level to process index).

This brings us to something called Replication Guides. Replication guides are an additional level of control (similar to list levels but even more specific) that we can use with DesignScript. They essentially allow you to specify the exact order of input levels to replicate over. Read the guide in the link to get more information and see how they work.

1 Like

You likely need to sort the list before trying to get an item by index, I think.


you need to chop indices by 1 and then flatten output by 1 to get and maintain your original list structure.

transpose the input list and access the required list by feeding the indices value into a matrix.
For example: indices values = 0,2,1,1.
Transpose the main input list and use list.getitematindex

List.GetItemAtIndex(lst<1>,idx<1><2>)
See if this works

4 Likes