# How to understand ScopeIf?

**URL:** <https://forum.dynamobim.com/t/how-to-understand-scopeif/85101>\
**Category:** DesignScript\
**Created:** [January 18, 2023, 2:41pm UTC](https://forum.dynamobim.com/t/how-to-understand-scopeif/85101 "2023-01-18T14:41:25Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [January 18, 2023, 2:41pm UTC](https://forum.dynamobim.com/t/how-to-understand-scopeif/85101/1 "2023-01-18T14:41:25Z")

</div>

Hello,

Can someone give me a practicle example?

 ![grafik](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/7/37b5bc1c13398b2f651734010a2eaa0394cf01de.png)  
how does it work and when i use it ?

KR

Andreas

---

<div class="post-metadata">

**Author:** ![Daan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daan/32/82246_2.png) [@Daan](https://forum.dynamobim.com/u/Daan)\
**Post date:** [January 18, 2023, 3:07pm UTC](https://forum.dynamobim.com/t/how-to-understand-scopeif/85101/2 "2023-01-18T15:07:08Z")

</div>

Hi @Draxl_Andreas ,

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

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [January 18, 2023, 3:09pm UTC](https://forum.dynamobim.com/t/how-to-understand-scopeif/85101/3 "2023-01-18T15:09:43Z")

</div>

@Daan ,

thats a node from clockwork Room.Doors …

 ![grafik](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/c/bcc17c38cd4b8ce95e73a6437b9e6f722756565c.png)  
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…

---

<div class="post-metadata">

**Author:** ![Daan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/daan/32/82246_2.png) [@Daan](https://forum.dynamobim.com/u/Daan)\
**Post date:** [January 18, 2023, 3:33pm UTC](https://forum.dynamobim.com/t/how-to-understand-scopeif/85101/4 "2023-01-18T15:33:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Alien](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/alien/32/40701_2.png) [@Alien](https://forum.dynamobim.com/u/Alien)\
**Post date:** [January 18, 2023, 3:39pm UTC](https://forum.dynamobim.com/t/how-to-understand-scopeif/85101/5 "2023-01-18T15:39:01Z")

</div>

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/d/2de8195d5dd1999c38da5064e19b6bad40719684.png)

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/4/b475664da65e473bd545cae0d693868b51eb6a27.png)

---

<div class="post-metadata">

**Author:** ![Alien](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/alien/32/40701_2.png) [@Alien](https://forum.dynamobim.com/u/Alien)\
**Post date:** [January 18, 2023, 3:47pm UTC](https://forum.dynamobim.com/t/how-to-understand-scopeif/85101/6 "2023-01-18T15:47:59Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/5/55291b7cc6fe8a2ade911448131e680ed1d46a7e.png)

A very simple bit of Python will work:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/a/8a7a64e44937248d6de9114d8b5a6ea99ec6b658.png)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/3/73cc64aee89ee6d176da6183f89c462dbd3ed54c.png)

---

<div class="post-metadata">

**Author:** ![pete.heibel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/pete.heibel/32/152649_2.png) [@pete.heibel](https://forum.dynamobim.com/u/pete.heibel)\
**Post date:** [January 18, 2023, 3:58pm UTC](https://forum.dynamobim.com/t/how-to-understand-scopeif/85101/7 "2023-01-18T15:58:24Z")

</div>

@Draxl_Andreas, I’ve used that code block syntax as a workaround when working with lists of differing lengths. Several others have [reported](https://github.com/DynamoDS/Dynamo/issues/6258) 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.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [January 18, 2023, 6:54pm UTC](https://forum.dynamobim.com/t/how-to-understand-scopeif/85101/8 "2023-01-18T18:54:45Z")

</div>

`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.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/8/0896b2cd2253dc01feee8fd7d2b4d842ecfed752.png)

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

> [@Alien](#):
>
> ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/5/55291b7cc6fe8a2ade911448131e680ed1d46a7e.png)

---

<div class="post-metadata">

**Author:** ![Alien](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/alien/32/40701_2.png) [@Alien](https://forum.dynamobim.com/u/Alien)\
**Post date:** [January 18, 2023, 7:08pm UTC](https://forum.dynamobim.com/t/how-to-understand-scopeif/85101/9 "2023-01-18T19:08:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [January 18, 2023, 7:21pm UTC](https://forum.dynamobim.com/t/how-to-understand-scopeif/85101/10 "2023-01-18T19:21:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michael\_Kirschner2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/michael_kirschner2/32/75576_2.png) [@Michael\_Kirschner2](https://forum.dynamobim.com/u/Michael_Kirschner2)\
**Post date:** [January 18, 2023, 7:52pm UTC](https://forum.dynamobim.com/t/how-to-understand-scopeif/85101/11 "2023-01-18T19:52:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Alien](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/alien/32/40701_2.png) [@Alien](https://forum.dynamobim.com/u/Alien)\
**Post date:** [January 18, 2023, 10:54pm UTC](https://forum.dynamobim.com/t/how-to-understand-scopeif/85101/12 "2023-01-18T22:54:31Z")

</div>

You mean Python right 😛

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [January 18, 2023, 11:05pm UTC](https://forum.dynamobim.com/t/how-to-understand-scopeif/85101/13 "2023-01-18T23:05:25Z")

</div>

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.
