[Request for Feedback] Refactored the "If" Node

Hello Dynamo people!

We have changed the functionality of the “If” node in Dynamo. Previously the “If” node would work like a conditional statement, similar to the inline condition in DesignScript. So when the ‘trueValue’ and ‘falseValue’ had list values of different lengths it would replicate over the shortest length. This was a little confusing to the users as they were seeing unexpected output. The same would happen with empty lists and null values.

To avoid this confusion, we have decided to update the “If” node functionality and the node would directly return the complete ‘trueValue’ or ‘falseValue’ based on the input ‘test’ condition. This would handle lists of different lengths, empty lists and null values. If the ‘test’ has a list of boolean values, the output of the “If” node will replicate on that list. Note that this node will replicate only on the ‘test’ input parameter.

We have a Dynamo build which has this new node and for now, this new node has the same name. We encourage you to try this build out and let us know if think of any other changes. We will be glad to incorporate them.

The old node is hidden from the library and the new node can be used. We are supporting backwards compatibility for this node till we completely obsolete the old “If” node. If you open up any old graphs with the “If” node, the graph will execute like before and the node will show a warning message to update it.

In order to use the DynamoCoreRuntime.zip files on windows operating systems, please use 7zip to extract the files or alternatively, manually unblock the zip archive before unzipping it. For more information on the DynamoCoreRuntime builds and how to setup your machine please see our wiki page.

New_If_Node.dyn (152.6 KB)

8 Likes

I assume that means it will continue not to support list levels?

1 Like

Does this mean the DesignScripts if function will not be updated with the new if node?

Hello @Nick_Boyts - We are happy to investigate support for List@Levels and Lacing should the need arise.

With the link to the ZIP file above containing the new If Node version - would you be able to show us use cases that it doesn’t cover, which List@Level would?

1 Like

@Steven the old If node used the following DesignScript code under the hood:
result = test_condition ? truevalue : falsevalue;
This DS conditional statement replicates over all 3 inputs, namely, test_condition, truevalue, and falsevalue.
The new If node, uses the following DS code under the hood:
[truevalue, falsevalue][test_condition ? 0 : 1];
This new code does not replicate over truevalue or falsevalue but continues to replicate over test_condition.
So to answer your question, the original DS conditional statement has not changed in behaviour. We have only replaced the underlying guts of the If node to make it more intuitive.

4 Likes

Honestly I’m not sure if I have anything off the top of my head, but I feel like I’ve ran into this situation before. At least with the new node it would only take some minor list duplication to get the same outcome. I’ll see if I can put an example together.

1 Like

Ok cool! We also couldn’t really figure out use cases that wouldn’t be served by this change :slight_smile: If anyone can showcase us them then great!

2 Likes

This is obviously a made-up use case so there are probably better ways to handle this, but this is essentially what I had in mind: a scenario where you have a list of booleans representing sublists within the true/false results.

Again, it wouldn’t take much to get the desired result with some minor list manipulation, so this isn’t really a big deal, but it could be done with list levels. I may also be missing something. :man_shrugging:

3 Likes

Thanks for the response @Aparajit_Pratap,

Has this style of DS always been around or is it new along with the IF node? More of a curiosity question.

Thanks,
Steven

1 Like

To simply answer the question… great news :slight_smile:

This has been the DS workaround for a while. Essentially just get the sublist at the specified index rather than filter a mismatched dictionary. Completely circumvents the IF node. :+1:

3 Likes

Yes, @Nick_Boyts is correct. It’s not a newly supported syntax in DS, just a terse syntax. Essentially it packs the true and false values into a list and then indexes it by a 0 or 1 depending on which is the output from the inline conditional (ternary operator). This is possible due to the fact that anything inside an indexer [] can be an expression as long as it results in an integer. By “new” code I meant it was “new” for the If node.

3 Likes

I was replacing old If nodes to the new kind. I got different results from the original and broke my graph.


Hence, I used RIE_If to stop getting a warning. How could I have used the new If? Levels?

Hello truevis,

The underlying behavior of the If node has been changed. Please refer to this comment from Aparajit to understand the difference in behavior between the old and new IF node.

The RIE_If node takes in a list for all the input parameters so there is no replication happening for that node.

To understand the list levels better, please refer to this post here: Introducing List@Level: Working with Lists Made Easier - Dynamo BIM

If you could share a sample graph with the inputs you have been using, it would be useful for us to help you get the desired result.