Using IF statements correctly?

Hi all, I’m looking for a bit of guidance on how to approach a workflow, as Dynamo handles IF statements a little differently to how I’m used to with excel and the like.
I’m currently working on a Model MOT tool to tidy up bits and bobs, and I’m offering the user a UI to select which cleaning options they want.

In the example below, you can see I’ve got a couple of python scripts to perform the actions, but I’d like some advice on how to get the boolean buttons to correspond with running the node or not. I’m effectively after an IF node that instead of outputting different values depending on a True or False, I’d like 2 outputs, so I can attach wires to the True output and to the False output. Hopefully that makes sense?

I might just be going about this completely the wrong way, so any suggestions welcome.

The short explanation is that Dynamo runs all nodes on execution. There is no way to conditionally run a node. Instead, you have to build the condition around what is returned in the output.

Can you clarify this? Are you wanting to prefilter your inputs to be those that are True and those that are False first? Or do you just want to provide a single input but with separate outputs? Currently you have one input per boolean so I don’t understand what the separate inputs/outputs would be. You already have that.

Hello @dan.buckingham,

Just use this if condition in your python nodes to make sure the code will only run if IN[0] is true.

if IN[0]:

This will run code if the Input is not false, null or empty. So it will also run if input is “banana”, or anything else.

For your case it may be better to write:

if IN[0] is True:

Then it will only run if the input is “true”.

3 Likes

Nick’s pretty much on the money, but you can sort of deal with this by sending nothing into a branch and something into another. Usually branches will just do nothing when fed empty data (although may trigger warnings).

Not always an option, but I’ve used it before. My slang term for this is a flipflop, where sometimes flip has something, sometimes flop doesn’t. Send flip into one branch, flop into another depending on a boolean condition.