What is the difference between If / Scope If nodes?

Only the simple question in the title

@faramawy ,

good question

#local varaible outside if
nums = IN[0]

OUT = []

for i in nums:

    if(i==2):
        b = i+2
        OUT.append(b)
    else:
        x = i +10
        OUT.append(x)

if nodes execute both branches of their input
scope if nodes do not.

1 Like

Thanks, but i guess you are taking about python, but i was asking about dynamo nodes, as there are a node called (If) and another nodes is called (Scope If) and actually i couldn’t understand the answer through you example, could you please simplify it.

1 Like

sorry, didn’t understand this either, i feel embarrassed :frowning:

1 Like

@faramawy ,

check out the dictionary!
https://dictionary.dynamobim.com/#/Core/Logic/Action/ScopeIf

ok, and i red this before, and it seems to be the same as (If) node does, am i wrong ?

1 Like

do you mean that (Scope IF) node is the stable version of (If) node ?

Nope. Both are stable. Both do exactly what they’re supposed to do. They have different use cases as explained in the linked post.

If there’s something specific you’re trying to do we can probably tell you which node to use and why. If you’re just generally interested then I’d suggest doing some more searching on the forum. There are plenty of topics covering the difference between the nodes.

You know what, i did a simple test inspired by what you said, and i think i understood something

but can you tell me what is happening here ?

And yes i need to do a specific function, so i renewed my query to find the best solution.

In the next screenshot, consider this is a script with 2 paths, 1 is red , 2 is blue
orange is the test
i need to go through the red path if test = true
else go for the blue path if test = false

what is may have understood, that Scope If node is here the solution as it may stop the path which i need to stop and activate the desired path, and correct me if i am wrong

This is a common misunderstanding of the ScopeIf node as well as how Dynamo graphs execute.

ScopeIf has a very specific purpose: execute the one conditional branch that matches the test condition. In your example, with the test condition being true, the addition node gets executed and the subtraction node does not. The reason ScopeIf gives you a cyclical dependency error in this case is because you’re running in Automatic mode so both nodes have already executed. It cannot prevent one branch from executing if it already ran.

As for using ScopeIf on your graph - it’s highly unlikely to work. For a branch to run (which comes before the ScopeIf node, not after) it must be completely independent from all other branches and not have any other interactions that would block the graph from running, like other dependencies and inputs. ScopeIf is really for use in custom nodes where it’s pretty safe to assume that a branch will be “disconnected” from anything that would typically cause these problems in the graph workspace, but it does still work in a graph, just less often and with more issues. You could possibly try moving your whole graph (or at least the 2 branches) into a custom node with ScopeIf, but that may not be plausible.

In additional to all that, this isn’t really the way Dynamo was designed to run. When you have two branches that run under certain conditions, Dynamo still has to execute both. So the best workaround is to control where the data goes, rather than what runs. This also means dealing with nulls or empty lists in the branch that “isn’t running” but that can typically be managed with a little extra effort.

Hopefully that clears some things up.

1 Like

honestly this error looks like a bug - I would expect this graph to function correctly.

It only occurs if you plug the inputs in when running in Automatic. If you connect everything in Manual and then switch to Automatic you don’t get any errors, even after the node has been executed and has a value. It seems like ScopeIf knows the difference between whether it caused the node to execute or whether it had already executed before ScopeIf.

1 Like

Many thanks to you, this is the complete answer and i think i got the point, and this post will be a reference to me and hopefully for others about the difference between If & ScopIf

Again and again, thanks for your time and effort, you and all who consumed there time to answer