Workaround with If statement and empty list

Hi, Can anyone help me with a work around for this to take the element when true. Also when theres an element in the empty I want it to take that one when its false.

The IF often fails when the 2 “answers” are of a different rank (ie a list and a value), it’s a lot more predictable when both items are lists or just 2 single items.

1 Like

I believe you could also use the ‘Scope if’ node when working with empty lists
image
image

The normal if node does not handle empty lists inputs correctly, the scopeif node does.

1 Like

Via Design Script:
indx = DSCore.List.IsEmpty(a) ? 0 : 1 ;
rslt = [a,b][indx];

1 Like

Thank you for the replies but still need a little more help please :slight_smile:

This worked but not for going the other way around.


My dynamo dosn’t quite agree with the scope if node. I gave it a go before but it did odd things like corrupts the script then id have to copy the script to a new script for it to work again.

I’m probably not implementing the design script correctly…

This ended up working from your ideas :slight_smile:


1 Like

I put the [a,b] list backwards based on the previous indexing. My bad.

1 Like

Both inputs need to be a list in that implementation. you forgot the [ ] around the value.

2 Likes