# Conditional execute

**URL:** https://forum.dynamobim.com/t/conditional-execute/29129
**Category:** Revit
**Tags:** dynamo
**Created:** [November 30, 2018, 3:49am UTC](https://forum.dynamobim.com/t/conditional-execute/29129 "2018-11-30T03:49:21Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![Ning\_Zhou](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ning_zhou/32/68283_2.png) [@Ning\_Zhou](https://forum.dynamobim.com/u/Ning_Zhou)
#### Post date: [November 30, 2018, 3:49am UTC](https://forum.dynamobim.com/t/conditional-execute/29129/1 "2018-11-30T03:49:21Z")

</div>

i have a list which maybe empty so is there a way to conditional execute the next node? and how to use If node?

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

---

<div class="post-metadata">

### Author: ![SeanP](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/seanp/32/42560_2.png) [@SeanP](https://forum.dynamobim.com/u/SeanP)
#### Post date: [November 30, 2018, 5:19am UTC](https://forum.dynamobim.com/t/conditional-execute/29129/2 "2018-11-30T05:19:12Z")

</div>

Use a List.FilterByBoolMask node. Connect it to your elemts coming in and the bool from the IsEmpty node. That will give you two lists out. One of Elements and then other of empty lists. Then you can do what you want with them after that.

---

<div class="post-metadata">

### Author: ![Ning\_Zhou](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ning_zhou/32/68283_2.png) [@Ning\_Zhou](https://forum.dynamobim.com/u/Ning_Zhou)
#### Post date: [November 30, 2018, 12:57pm UTC](https://forum.dynamobim.com/t/conditional-execute/29129/3 "2018-11-30T12:57:55Z")

</div>

thanks Sean1, but i don’t think it’s working, if the original list is empty then both output of FilterBoolMask are empty, List.LastItem node will generate warning no matter what.  
my questions:

1. how to “not connect” to next node if certain condition i.e. empty list
2. how to use If node, i don’t understand that “simple” node yet

---

<div class="post-metadata">

### Author: ![SeanP](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/seanp/32/42560_2.png) [@SeanP](https://forum.dynamobim.com/u/SeanP)
#### Post date: [November 30, 2018, 1:07pm UTC](https://forum.dynamobim.com/t/conditional-execute/29129/4 "2018-11-30T13:07:52Z")

</div>

Would you share a complete image of your graph? If the Entire list is empty, what are you trying to get with “List.LastItem”?

---

<div class="post-metadata">

### Author: ![Ning\_Zhou](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ning_zhou/32/68283_2.png) [@Ning\_Zhou](https://forum.dynamobim.com/u/Ning_Zhou)
#### Post date: [November 30, 2018, 1:42pm UTC](https://forum.dynamobim.com/t/conditional-execute/29129/5 "2018-11-30T13:42:37Z")

</div>

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

---

<div class="post-metadata">

### Author: ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)
#### Post date: [November 30, 2018, 1:56pm UTC](https://forum.dynamobim.com/t/conditional-execute/29129/6 "2018-11-30T13:56:24Z")

</div>

Ty something like this. There will be a warning, but the node should run as inteded either way.

You may want to check if the Elements.Delete works with empty lists.

 ![Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/e/5e9d8aef36ba2e910c9f47f2009e18446abff208.png)

---

<div class="post-metadata">

### Author: ![SeanP](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/seanp/32/42560_2.png) [@SeanP](https://forum.dynamobim.com/u/SeanP)
#### Post date: [November 30, 2018, 2:17pm UTC](https://forum.dynamobim.com/t/conditional-execute/29129/7 "2018-11-30T14:17:56Z")

</div>

Try this, it shouldn’t throw and error if the list is empty.  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/6/461fc1a4a90de244c3516f67b5bf704a4138317f.png)

---

<div class="post-metadata">

### Author: ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)
#### Post date: [November 30, 2018, 2:23pm UTC](https://forum.dynamobim.com/t/conditional-execute/29129/8 "2018-11-30T14:23:59Z")

</div>

Really nice @SeanP !

Didn’t knew that List.Map could avoid those kind of situations 🙂

---

<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: [November 30, 2018, 3:47pm UTC](https://forum.dynamobim.com/t/conditional-execute/29129/9 "2018-11-30T15:47:56Z")

</div>

You can also use scope if node for this - but it’s a bit tricky - the two input branches cannot share any nodes or data.

---

<div class="post-metadata">

### Author: ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)
#### Post date: [November 30, 2018, 3:52pm UTC](https://forum.dynamobim.com/t/conditional-execute/29129/10 "2018-11-30T15:52:48Z")

</div>

Wouldn’t the condition being defined by one of the branches (the case here) create a circular dependancy ?

---

<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: [November 30, 2018, 4:00pm UTC](https://forum.dynamobim.com/t/conditional-execute/29129/11 "2018-11-30T16:00:48Z")

</div>

have to create two independent copies of the same list - scopeIf only matters if you want to avoid executing one of the branches.

If you only care about the data passed through - then the if should work -

you can also use a ternary operator `?` or if statement inside an imperative block.

---

<div class="post-metadata">

### Author: ![Ning\_Zhou](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ning_zhou/32/68283_2.png) [@Ning\_Zhou](https://forum.dynamobim.com/u/Ning_Zhou)
#### Post date: [November 30, 2018, 5:41pm UTC](https://forum.dynamobim.com/t/conditional-execute/29129/12 "2018-11-30T17:41:07Z")

</div>

can anyone explain how to use If node and ScopeIf node? sounds simple enough but i don’t get it yet

---

<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: [November 30, 2018, 11:08pm UTC](https://forum.dynamobim.com/t/conditional-execute/29129/13 "2018-11-30T23:08:45Z")

</div>

[http://dictionary.dynamobim.com/#/Core/Logic/Action/ScopeIf](http://dictionary.dynamobim.com/#/Core/Logic/Action/ScopeIf)

---

<div class="post-metadata">

### Author: ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)
#### Post date: [December 1, 2018, 12:14am UTC](https://forum.dynamobim.com/t/conditional-execute/29129/14 "2018-12-01T00:14:35Z")

</div>

Nesting the if statement in an in-line function that does nothing can also prevent the error.

---

<div class="post-metadata">

### Author: ![m.owens](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@m.owens](https://forum.dynamobim.com/u/m.owens)
#### Post date: [June 15, 2021, 5:13pm UTC](https://forum.dynamobim.com/t/conditional-execute/29129/15 "2021-06-15T17:13:50Z")

</div>

It seems you are the ScopeIf expert here, so I wonder if you might help me with trying to wrap my head around how to implement this in my definition.

I have a script which is updating elements based on excel-data. If it can match data, it will execute one branch of the script; if it cannot match data it will place new elements.

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

As is often the case, all of the data can find a match, and one branch receives an empty list.

Here is where the empty-list shows up, and where i would like to stop the nodes from executing when receiving an empty list:

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

I am simply trying to get ride of “meaningless” errors when an empty list is sent to a node. It sounds like ScopeIf can help here, but I have no idea how I go about using it.

---

<div class="post-metadata">

### Author: ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)
#### Post date: [June 15, 2021, 5:20pm UTC](https://forum.dynamobim.com/t/conditional-execute/29129/16 "2021-06-15T17:20:52Z")

</div>

Fucction.Create and Function.Apply would suppress the warnings and likely keep things neater over time.

---

<div class="post-metadata">

### Author: ![m.owens](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@m.owens](https://forum.dynamobim.com/u/m.owens)
#### Post date: [June 15, 2021, 6:11pm UTC](https://forum.dynamobim.com/t/conditional-execute/29129/17 "2021-06-15T18:11:43Z")

</div>

I am sure that your response gets me to where I need to go…unfortunately, I don’t comprehend it.

When it comes to string basic nodes together, I can accomplish what I need to. When it comes to using more “advanced” nodes like “function.compose” and “apply” I am afraid that I am a novice.
