If ( then , else) in dynamo

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?


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

11-19-2015 1-01-54 PM

1 Like

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.


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

if somecondition:
</code>    # do something
elif somecondition:
    # do something
elif somecondition:
    # do something
    # 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>

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


if (condition)

{ // do this thing



//do that thing


you may need to put this inside an imperative block like


result = [imperative]{

a = 0;


a = 10;


return = a;


(not tested)


1 Like

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:











Best Regards.