Same if statements return different results...?

Anyone knows why these two apparently identical tests return different results?

If the reason is that IF requires “equal number of arguments”, my question becomes:
what formula or OOTB node would return an argument (or list) if the argument or list is not Null, and an Empty.list if the argument is Null?

“Scope.If” has never worked for me, so that is not an option (that node consistently breaks my graphs, in weird ways, everything just stop working / running).

Another question would be: considering that almost never the 3 argument of my IF nodes are the same length, why is such a node designed this way? Basically the node does not allow lacing…?

thank you



@Giovanni_Succi please have a look a this post If node or conditional statement returning only the 1st element of a list

Is “room” true or false? How about aardvark? Cantaloupe? Purple? 1? One?

As a start your if statement should always be driven by a boolean (meaning true or false) not an object.

Thank you Salvatore, that helped.

Jacob, normally an object returns “True” unless its Null, or with no value.

“x?” works in a number of cases, not just with 0 / 1 or True / False…

In any case, even using strictly boolean values, IF has this argument length requirement which make it useless for many applications, which is a the base of our problem.

The tiny Python script or even the design script returning just an index and then the appropriate list may work… Or, just “ThisOrThat” node, but as a rule I try to use the least amount of dependencies as I can. So finding a block note that does an IF is what I was Looking for…

Thank you all



Why an empty list? A null is more likely what you’re looking for.

You’re supplying a list for the True argument and a list for the False argument. The list for your False argument just happens to be empty. You’re creating a dictionary with all keys and no values. So the IF statement is doing exactly what you asked. It’s return a list of objects for each input - they’re just all empty. Your list structure also doesn’t really warrant returning an empty list. You’d be converting a 1D input into a 2D output for certain objects.

Empty lists are compatible with other operation down the graph (like list set difference), while Null values are not.

So, I need to control the flow of data down stream, and I need an empty list if I am getting a Null at this juncture.

I constantly need to replace Nulls and missing values because Dynamo runs every node, every time, and there is no way to conditionally run branches of the graph.

In any case, Nick, I am not going to pretend I understand why the IF node behaves the way it does. In my screen shot, the same test returned both a THEN argument and an ELSE argument, depending on the arguments provided.

This is not intuitive for people not into computer science.

IF [test] THEN [a] ELSE [b] should work regardless of what exactly [a] and [b] are.

I know there must be a perfectly good reason for the IF node behavior (since everybody obviously think this is not a bug), but I also know that I just don’t need it because most of the time my THEN and ELSE arguments are not consistent (let alone of equal length).

Hopefully I will be able to replace the IF node with the node block: i= x?1:0; [opt1,opt2][i];

thank you


Jacob, here is a sample showing how I use “X?” to clean up my data:

Only empty lists “break” the testing and return themselves.




It may not be intuitive, but that’s why I’m trying to help you understand why it’s acting this way.

This is for returning entire lists. This is going to give you the same output.

The point I’m trying to make is that you are trying to use your inputs as different list structures and that’s where (most of) the issues are coming from. You’re essentially telling Dynamo this:
Because the inputs are all lists, Dynamo assumes that they all line up (index to index). So when it looks for the item in the ELSE input there is none. The empty list has no items so the function fails.

All that is to say that Python is your only (rational) option here. However, even if you get the results you’re looking for I think your outputs will be inconsistent.

The first Python option shows what I think you’re looking for. The problem with this is that your TRUE results return a single value x while your FALSE results return a list Empty List which may result in inconsistent list structures down the line. The second Python option returns the values in the same structure. Each result is a list, empty or otherwise.

This is the Python code for the first node. If you want your values all returned as lists you just need to put the appended x value in brackets to form a list.

dataEnteringNode = IN
xList = IN[0]
out = []

for x in xList:
	if x:

OUT = out
1 Like