List get item at index fails

Goodday,

Today i ran across an warning in one of our dynamo scripts which hasn’t occured before.
Used the script multiple times before without any warnings.
First screenshot is the working version, Second one contains the warning.
Any solutions?


Have you just tried replacing the node?

Try removing the nested empty lists from the List.AllIndicesOf Node.

@Alien Tried, but it didn’t work

@daniel1 I want to keep the empty lists for the structure of the whole list, otherwise i have to find a way around it to reorganize the list

From my experience, the List.GetItemAtIndex node typically errors out when it is fed with nested empty lists. I would restructure the graph in order to prevent the issue. Without seeing all of the nodes and dropdown previews I can only offer a few bits of advice.
Input the List.AllIndicesOf node into a flatten node and a count node at level two. Input the flatten node and the count node into a chop node to reproduce the original structure without the empty lists.

Most nodes will fail this way when given an empty list as the first item. It’s always best to clean your data or account for the issue as you go.

3 off the top of my head options to deal with the bad data:

  1. Use a List.Map method or a Function.Apply method to force the full list to process despite the error. Careful as someday this could suppress a “stop the presses” warning you would want surfaced.

  2. Build up the list by adding value which will fail but will ensure continued processing via forcing List Levels, a String may work in this case. Careful as this is effectively ensuring a warning in all cases.

  3. Add a list of [0] and an index of 0 to the larger data structure, ensuring the first attempt at ItemAtIndex always has valid input, and then remove the resulting initial zero from the result. Careful as this could become a repeat process that will slow the graph down on big data sets by adding new lists into the memory.

  4. Revisit the larger structure of the graph and/or workflow. Hard to know how much this would entail with the data given. This is likely the most likely but will also require the most soul searching on your end (both for you and anyone else who may be consuming the workflow).

3 Likes

Recently updated to Revit 2021, Issue seems to be fixed in Revit 2021, All nodes i’ve used in dynamo seem to work when they’re fed with nested empty listst. Huge relief for my dynamo scripts.