Struggling with If statement or While loops - in Dynamo

I’m struggling with If statements & while loops.

I understand IF and WHILE statements in other programming but in Dynamo and or Python in Dynamo I’m lost. I can make the if statements in dynamo and get the condition but then after I have the condition met I have no idea how to proceed. I need to understand to create additional walls in Revit based on the following logic. I expect WHILE should work best but it is odd in Dynamo and have found very little useful information. I understand the basics of Python and probably can sort out how to make a loop work in Python. But I get lost when trying to apply the python information results to creating the following revit walls.

I have a condition that will always be an integer between 1 to 6 a separation distance of ‘W’ for Width for spacing between the walls.

I start by having an Existing Revit Wall #1.

If the integer value =

1 then I do nothing. (Result: 1 Existing Revit Wall)
2 then build 1 Revit wall #2 W distance away Existing Revit wall #1 (Result: 2 walls)
3 then also build 1 Revit wall #3 + W distance from wall #2 (Result: 3 walls)
4 then also build 1 Revit wall #4 + W distance from wall #3 (Result: 4 walls)
5 then also build 1 Revit wall #5 + W distance away from wall #4 (Result: 5 walls)
6 then also build 1 Revit wall #6 + W distance away from wall #5 (Result: 6 walls)

Any thoughts or good samples to refer to that allows me to use IF or WHILE statements to create multiple walls depending on the INTEGER condition?

This looks less like an IF or WHILE statement and more like a sequence.

You’re just looking for n-1 walls at W spacing. Try something like Curve.PointAtParameter based on these values.

And to respond to your original question, IF statements work just the same as any other programming language except that the conditional outputs must be equal in length. WHILE statements are almost never used in Dynamo (Python is a different story) due to how Dynamo automatically iterates through list inputs.

I don’t have a curve on my revit file. Yes this is about iterating… I also thought about using a foreach loop but does not exist in Dynamo. Your suggestion about Dynamo iterating through a list makes sense. Do you have an example of how ‘as dynamo iterates’ through a list it creates an object, in this case a wall? or another revit object. The part that is confusing to me is the ‘creation of a new revit object’ as it iterates. Also, still a little unclear about the iteration in dynamo. I have seen it being used but am confused when it comes to creating a new object each time it iterates.

You would create a dynamo curve to use as a guide. I’m assuming it would be an extension of the Wall 1 location curve. Then you create a sequence, based on your n-value, to plot out points along that curve.

Dynamo “iterates” in that it is smart enough to loop a node function over multiple inputs. You can even change how these inputs behave depending on things like list structure, lacing, and list levels. This all happens in a single “transaction” though. Dynamo does not run the first input, stop, check that a condition is met, and then move on to the next input value. These conditions have to determine the inputs beforehand.

In your case, it’s easy to determine what all our final input values will be without having to use a looping function. Therefore we can get our input values ahead of time and then create all the geometry at once.


1 Like

Your sample was exactly what I needed. Here is my finished code that can be used by anyone to make an array of walls depending on number of bays and and width up to 6 bays. Thanks so much for the help! :slight_smile:

sequence walls.dyn (45.5 KB)

1 Like