IF-Condition - NULLS and EMPTY LISTS

Hello again Dynamo friends :slight_smile:

I´m making a script ready to work also if wrong inputs are selected by the user.
Now i have the problem, that Userinterfaces get triggered allthough they should not run.
This is because the IF-Condition (codeblock) doesn’t work with nulls and empty lists as “test”-input.

In the following example a “true” value is passed even there is nothing (null) to test:

In the next example i added a “null-filter”. It works for nulls, but now it doesn`t work for another case where i get empty lists:

What can i do to stop the UI from running?

If you want to know why I’m even getting these null values, this is also because of empty lists and IF-blocks:

Would be happy about any advice! Thanks in advance :slight_smile:

So, if the input is either null or Empty List you want the output to be Empty List and if the input is something different from those values, do you want it to be true?

Hello Edson :slight_smile:

The UI should run if the “List.isEmpty” node gives a “false” output. That works.
In any othe case the UI should not run. A UI that gets a “false” trigger will add 1-2 seconds to the script runtime. I use the “List.Empty” nodes to avoid that problem.

Maybe i should use little python scripts instead of the IF-blocks?

Count the number of items and check if it is greater than 0. :slight_smile:

1 Like

Try this:

Test = x;
True_value = [];
False_value = true;
	return (DSCore.List.IsEmpty(Test))? True_value:
	(Test==null)? True_value: False_value;

Thank you for your help, works perfect :slight_smile:

I will need codeblocks like this in a few scripts, now i know how this works and can edit it for other cases if necessary :slight_smile: :smiley:


Fun fact, my Userinterface was running again when it should not.
And the problem was, i forgot to connect a wire to the IF-Condition-Codeblock :smiley:

So for some reason it gives a true value if nothing is connected:

Not really a problem tho^^

1 Like

After a few days of thinking and testing i have an additional question.
When i use an empty list as true-value or false-value it does not work with the associative method.
It only works with the imperative method. Is there any explanation for that, or should i just accept this? :smiley:

This intrigued me two months ago and after a while I just decided to accept it haha.

1 Like

Associative code applies list lacing and levels to all functions. The results are ‘associated’ to the data structure given. This is somewhat unique to Dynamo,

Imperative code requires that the code itself describe the conditions to run in - hence the need to use a For loop when nested lists are in play.

This paper has some further reading if you’re interested: http://papers.cumincad.org/data/works/att/ecaade2013_297.content.pdf

My guess as to why it fails: Because associative code is used by default, you are seeing Dynamo attempt to iterate over a non-interable object (doubles), likely causing a warning which is suppressed by wrapping it in another function. As a result the If statement isn’t getting any input, so it isn’t returning any values in associative code. Try adding an @L2<1> To see what happens. In the imperative code you haven’t specified any loop, so it is looking at the list of numbers as an object rather than the contents.


I take it back - it’s the empty list which is causing this to fail. Associative code means it will only continue for a length that is equal to the lowest number of inputs, and since one of the inputs in the If statement is an empty list, it won’t ever give more than an empty list.

This associative method works just fine though:

i = DSCore.List.IsEmpty(x@L2<1>) ? 0 : 1;
r = [[],42][i];