# If ( then , else) in dynamo

**URL:** <https://forum.dynamobim.com/t/if-then-else-in-dynamo/2556>\
**Category:** DesignScript\
**Created:** [November 18, 2015, 9:45am UTC](https://forum.dynamobim.com/t/if-then-else-in-dynamo/2556 "2015-11-18T09:45:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dmitrijs\_Korolenko](https://avatars.discourse-cdn.com/v4/letter/d/b38774/32.png) [@Dmitrijs\_Korolenko](https://forum.dynamobim.com/u/Dmitrijs_Korolenko)\
**Post date:** [November 18, 2015, 9:45am UTC](https://forum.dynamobim.com/t/if-then-else-in-dynamo/2556/1 "2015-11-18T09:45:08Z")

</div>

Good day,

So I am creating a script that would list windows in the project and the orientation they are facing. I have gotten as far as defining the face azimuth value (0-360 degrees) to each window but now am stuck in trying to convert that to a string output (North, North-East, East etc).

The only way I can imagine that working is through some kind of if,then,else function going “If azimuth is in between 22.5 and 67.5, then North-East, else go to next check…”

Has anyone encountered something similar? How would an if,then,else function with multiple “elses” look in python? How do you check if a number is within a certain range in dynamo?

Regards

---

<div class="post-metadata">

**Author:** ![Johnes\_Hou](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/johnes_hou/32/9469_2.png) [@Johnes\_Hou](https://forum.dynamobim.com/u/Johnes_Hou)\
**Post date:** [November 18, 2015, 11:41pm UTC](https://forum.dynamobim.com/t/if-then-else-in-dynamo/2556/2 "2015-11-18T23:41:07Z")

</div>

Use FamilyInstance.FacingOrientation query the windows Vector and Rhythm package Wall.NorthSouthEastWest Will do the rest.

![11-19-2015 1-01-54 PM](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex022/uploads/dynamobim/original/2X/9/9926436069d9d08f1f138b1eb0e702ae1f18c896.jpg)

---

<div class="post-metadata">

**Author:** ![Dmitrijs\_Korolenko](https://avatars.discourse-cdn.com/v4/letter/d/b38774/32.png) [@Dmitrijs\_Korolenko](https://forum.dynamobim.com/u/Dmitrijs_Korolenko)\
**Post date:** [November 19, 2015, 5:32am UTC](https://forum.dynamobim.com/t/if-then-else-in-dynamo/2556/3 "2015-11-19T05:32:15Z")

</div>

Thanks Johnes. Didnt know that node worked for windows (node naming, amirite?). What If I wanted to make that a bit more resolute, ie showing North-East, South-West and other orientations? Going to dig though the Rhythm node, maybe ill have enough brain power to figure it out.

---

<div class="post-metadata">

**Author:** ![Konrad\_K\_Sobon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/konrad_k_sobon/32/8838_2.png) [@Konrad\_K\_Sobon](https://forum.dynamobim.com/u/Konrad_K_Sobon)\
**Post date:** [November 19, 2015, 12:40pm UTC](https://forum.dynamobim.com/t/if-then-else-in-dynamo/2556/4 "2015-11-19T12:40:50Z")

</div>

Dmitrijs,

In python to do multiple if else function you can do this:

```auto
if somecondition:
</code> # do something
elif somecondition:
    # do something
elif somecondition:
    # do something
else:
    # do something

in Dynamo you can do a simple if else with a Code Block:

somecondition ? thishappensifTrue : thishappensifFalse

so if you wanted to nest them for multiples you could do this:

somecondition ? thishappensifTrue : someotherCondition ? thishappensifOtherConditionTrue : thishappensifotherconditionFalse

I know its not the prettiest but should work.</pre>
```

---

<div class="post-metadata">

**Author:** ![Michael\_Kirschner](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/michael_kirschner/32/237_2.png) [@Michael\_Kirschner](https://forum.dynamobim.com/u/Michael_Kirschner)\
**Post date:** [November 20, 2015, 10:07pm UTC](https://forum.dynamobim.com/t/if-then-else-in-dynamo/2556/5 "2015-11-20T22:07:29Z")

</div>

in code blocks you can use if and else as well,

&nbsp;

if (condition)

{ // do this thing

}

else{

//do that thing

}

you may need to put this inside an imperative block like

&nbsp;

result = [imperative]{

a = 0;

if(100\<200){

a = 10;

}

return = a;

}

(not tested)

&nbsp;

---

<div class="post-metadata">

**Author:** ![Dmitrijs\_Korolenko](https://avatars.discourse-cdn.com/v4/letter/d/b38774/32.png) [@Dmitrijs\_Korolenko](https://forum.dynamobim.com/u/Dmitrijs_Korolenko)\
**Post date:** [December 3, 2015, 10:45am UTC](https://forum.dynamobim.com/t/if-then-else-in-dynamo/2556/6 "2015-12-03T10:45:01Z")

</div>

Konrad, Michael,

Many thanks. Managed to make it work! And the code block processes a list of 100+ values in seconds, when some of the monstrosities I’ve built out of nodes took ages! Just goes to show the inherent inefficiency of visual programming I guess.

The end result looks like this:

![Capture3](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex022/uploads/dynamobim/original/2X/c/c12e83b2afb7f4ff8a338e2d114a4808a41d144c.gif)

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

Best Regards.
