Avoid error because of empty list

I have developed an algorithm that do different stuff in case of existing (duplicated items) or not existing elements. Therefore, if there only exists duplicated items or only not duplicated the boxes appear yellow showing some errors have occurred. I would like to avoid then as the code is working as it has to, only doing the staff it is needed.

I append an image of the algorithm in case it helps:

Thank you very much

I would like to explain that it works as 2 ways or branches:

  • Both branches work (there are existing levels and unique ones)
  • Only one branch works (all duplicated or all unique)

First it’s about understanding what your nodes can handle and what they can’t. Many nodes, including Level.ByElevationAndName, will successfully pass an empty list but fail when given null or incorrect values. Make sure you’re passing an empty list rather than a null value (or something else) when you have nothing in that branch.

The second thing to understand is that Dynamo executes the graph “all at once”. You can’t really have it execute only part of your graph. This is why you have to deal with successfully passing empty lists or otherwise managing an “unused” branch. The only way to truly get away from this is with python or combining everything into a code block. Within a singular code block you can often bypass warnings by only executing a function (or list of functions) when a condition is met. Often this is done with an If statement or a custom function.

1 Like

Thank you very much. I have realized that the problem was getting an item with an index. I have already solve it using a simple python script. Now I understand a bit more about dynamos flows