If - Statement Output

If Statements have been discussed on various time here. However in digging through those I didn’t seam to find this particular issue.

What I want is to test for a true of false condition. Then based on that either get the complete list or a portion of the list. In the attached image, I am showing taking the “First” or “Complete” list.

For some reason, when different length list are input into the IF statement it will always return a list of a standard length.

I would expect the input to be just past through. This has been attempted with both the If node and the formula node as shown.

Would creating a Python or Func provide a different output and use of the “if” statement?

1 Like

Thats a current limitation with that type of If node. Use ScopeIf from the Core > Logic library if you want to return lists of different lengths.

Change the lacing to longest/shortest on your formula nodes.If that does not work, try with this short python script:

OUT = IN[1] if IN[0] else IN[2]

@Mike_Engel1: Indeed, the problem seems to lie in the lacing:

It appears to be a

There was another discussion on “ScopeiI” (I apologize for not having the link currently) that references not to use “ScopeIf” in the work space, it is only intended for use in “Custom Nodes” While I do not understand the why. I can confirm when attempting any use of it, nodes became null, many instabilities, and some very odd situations. Once I removed it from the work space, it began to work again.

I think you missed something
One Lacing does not affect the out list length, see new image here, with lacing both shortest and longest.


Two

I see longest lacings and no lacing (circles), but no shortest lacing here (single bar), or yes? :neutral_face:

Sorry, I didn’t see that, I read too fast, a bit tired I think :expressionless:

here, that’s what they called " old_if "

3 Likes

Another clever way I found on github (https://github.com/DynamoDS/Dynamo/issues/6491)

7 Likes

Yeah , good one . Amazing

Thank you for all your responses.
Some great solutions!

Still not sure of the Intent/why of the Behavior of the basic If Node, but oh well, At least we can understand how.

There are a couple of things that are mentioned on the dictionary

http://dictionary.dynamobim.com/#Core-Logic-Action..If

IF replicates on all nodes AS THOUGH SET TO SHORTEST. You can see the reason for this in the attached examples, especially when looking at what the results are when LONGEST is applied to a formula node and the “short” branch of the conditional is passes through. These changes were also made to allow predictable behavior when using single boolean inputs or a list of booleans.