How to understand ScopeIf?

Hello,

Can someone give me a practicle example?


how does it work and when i use it ?

KR

Andreas

Hi @Draxl_Andreas ,

What exactly are you trying to do? What do you want to test?

1 Like

@Daan ,

thats a node from clockwork Room.Doors …


I do not understand the sence… what am I feeding to it (?)

what can i do? Do i work with list, ranges, bools, so how can i understand the flow…

Is this a custom node you unpacked? It seems like the ScopeIf+ node acts as a simple if-gate here to switch between the phase which has been input by the user or, if there is no input by the user, the last phase from the Document.Phases list.

image

image

1 Like

Personally I don’t like the OOTB IF nodes. They break far too easily.
See below

A very simple bit of Python will work:

1 Like

@Draxl_Andreas, I’ve used that code block syntax as a workaround when working with lists of differing lengths. Several others have reported the regular IF node cropping the result at the length of the shortest list input. However, I believe this functionality has been merged into a more robust IF node in the latest version of Dynamo.

1 Like

ScopeIf is typically meant for use inside custom nodes. It often fails when used in the graph environment (though it can work if used carefully). The purpose of ScopeIf is to only execute the nodes connected to the conditional input matching the test condition. i.e. If your test condition is true then the nodes feeding the true input will run as expected and return an output while the nodes feeding the false input will not execute at all.

You can see here that the nodes return nulls even though ScopeIf still returns the correct value.

The problem with using this node in the graph environment is that you often have inputs that connect to other nodes that still need to run regardless of the scoped execution. In this example the test condition is tied to one of the scoped inputs which makes a cyclical dependency on having to execute both conditions in order to determine the test outcome. This cause everything to fail.
image967×314 32.9 KB

5 Likes

Oo, didn’t know it was for inside custom nodes.
I find it works slightly better than the regular IF node in the workspace.
Still fails regularly tho.

1 Like

As @pete.heibel mentioned, the standard If node has been updated to better handle list manipulation so it shouldn’t be much of an issue anymore. Either way, it’s all about using the right tool for the job.

1 Like

yeah, it should really be a warning when used like this- ie when any of the branches are not complete independent sub graphs.

2 Likes

You mean Python right :stuck_out_tongue:

Python is great for complex conditional statements, but I honestly use a code block more often just because it’s quick and easy. My point is that it’s better to know when to use one option over the other than to just rely on the one you know best. But it can be difficult to break those habits for sure.

2 Likes