GetItemAtIndex remove warning on empty list (custom node?)

Hello Forum

I would like to remove the warnings I get on the GetItemAtIndex node for empty lists.
With elements:


Without elements = warnings:

I have tried replacing with design script, but this still gives a warning and I have tried a simple python node, but this also gives a warning. I noticed packaging it into a custom node seems to ignore the warning, but I am not getting the same values out now from the custom node.

Could I ask: 1) any ideas for removing the warning from the GetItemAtIndex for empty lists? I have tried cleaning the list but no luck, as @jacob.small suggested in this post: List get item at index fails - #7 by JacobSmall

Or 2) Is there something I am doing wrong with the custom node to not get the correct output? The list levels are being altered by making it a custom node.

Any ideas would be greatly appreciated.

Many thanks
Tim

Here is inside the custom node if it helps…

Many thanks

Hello @TimGreatrex

I build my graphs in a way to give no errors. I´m using this codeblock:

image

x;
[Imperative]
{
	return (List.IsEmpty(x))? []:
	(x==null)? []: x;
};

Item at index looks like this:

And hundreds of variations:

1 Like

Hi

Thank you very much for sharing this, this is great. I will give these a try.

Thank you again!
Tim

When using an imperative function it will not give null or index errors but always null if there is no result.

A null check seems not necessary, also IsEmpty. It is better to check if the index is not exceeding the length of the array. Then it is also not needed to use Imperative.

In case of null, an empty array or an incorrect index it will return null, without warnings.

A simple conditional statement will work.

1 Like

Hi Anton and Nick

Thank you for this! I will give these a try also.

Many thanks again
Tim

Yes, it is. If you want to avoid errors in general.
The null results you get will give a lot of errors in the nodes that are connected.
Passing empty lists usually won’t, so for my purposes this is the way to go.

Avoiding the ItemAtIndex Error won’t help much if it leads to 10 other errors in a graph :smiley:

Hi Nick

The DS conditional statement worked well. I did Node to Code on the List.GetItemAtIndex to get the syntax for the levels to add to your conditional statement.
When empty list fed through:

With data:

Many thanks again all for your fantastic help!
Tim

3 Likes

Those nulls will get you in trouble @TimGreatrex ^^ Empty lists are your friends, nulls are evil :smiley:

@Anton_Huizinga

List counting is a solid alternative to “my” method:

Hi Gerhard

Thank you for this. I did encounter a number of nulls down the graph, and had to use Clockworks replace nulls with empty lists. I will give your DS another look, many thanks for this.

Tim

1 Like

For your understanding, the imperative code is needed because i want to give an empty list as an output. This is not possible with an associative code, the codeblock would always put out an empty list:

see also: IF-Condition - NULLS and EMPTY LISTS

Hi Gerhard

Thank you for the link. I think I need to spend more time with DS syntax to get my head around it. Your code is working except I cannot get the list levels correct.


The highlighted list is correct. I am sure it is really simple!

Many thanks
Tim

It seems like a wrong choice to return an empty list instead of trying to figure out where the null comes from. You have a hard time to walk through the code to find the issue, if there is any. I rather would add an explicit node to filter the nulls or replace them if it is really necessary to work with empty lists. The warnings are there for a reason, not to be suppressed :wink:

You check if the list contains at least one item, it is nothing more than checking for emptiness. What I did was checking if the list contains at least as many items as the given index. That is more solid.

1 Like

You plugged in to the wrong output :smiley: But it wouldn´t have worked anyway^^

There are many different solutions.

Thank you again Gerhard. This is a great help.

Cheers
Tim

is OOTB GetItemAtIndex @ Level written in Python? factory or anyone has Python version available for sharing? i’m mainly C# guy but use Dynamo heavily (OOTB nodes only + Python), currently Node to Code w/ added conditional statement seems the best (?) solution but not stable, List.Map (as mentioned by JacobSmall) seems not working at all levels i.e. L1 seems not working well

Function.Apply might work out better.

thanks Jacob, how to use it? looks like result is not desired
image

This DYN should show how to utilize the node.

As far as how to use it with your data, I don’t know as I can’t see how you have structured it.