# Growing Structure, Iteration/LoopWhile/ListMap

**URL:** <https://forum.dynamobim.com/t/growing-structure-iteration-loopwhile-listmap/44894>\
**Category:** Geometry\
**Tags:** dynamo\
**Created:** [December 27, 2019, 6:00pm UTC](https://forum.dynamobim.com/t/growing-structure-iteration-loopwhile-listmap/44894 "2019-12-27T18:00:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanielArch](https://avatars.discourse-cdn.com/v4/letter/d/e480ec/32.png) [@DanielArch](https://forum.dynamobim.com/u/DanielArch)\
**Post date:** [December 27, 2019, 6:00pm UTC](https://forum.dynamobim.com/t/growing-structure-iteration-loopwhile-listmap/44894/1 "2019-12-27T18:00:07Z")

</div>

Hello everyone,  
im trying to create a self growing 2d structure based off rectangles, later replaced by more complicated floors.The goal is to get a variable number of rectangles that are connected to each other. I started with a grid and placed a rectangle. Then Dynamo picks a random corner and a random angle from this rectangle and creates another one with this information. I copied this 20 times and it works, but i want to be more flexible so that i can change the numbers with a slider and dynamo automatically creates the rectangles. Therefore i dealt with LoopWhile, Custom Nodes, DesignScript and now im back to List.Map. Im pretty much a beginner and using Dynamo only since 3 Months. I cant get behind the problems that occur, whether its functions not working in the Loop or the LoopWhile crashing. There are too many Files where i tried it, so im uploading the recent three. I looked up other examples and tried to use them for this, but i guess im not 100% understanding it and therefore can´t find the solution by myself. Maybe there is a way easier solution to this. Nevertheless im linking them here (also the recent ones):

> [@Any Simple Loop Code using Design Script Examples?](https://forum.dynamobim.com/t/any-simple-loop-code-using-design-script-examples/7833/3):
>
> Thanks this has been a great help today, i have been able to edit it to work with one of code but when i change the process it does not work as expected. The code on the left works but the code on the right fail to return an output, but both codes work as expected when coded outside the loop. I need the code logic on the right to work as the move is only a simple example, when i get this to work i can add more complex transformations. Broken Loop Code def move\_cubes\_shift(cubes:va…

> [@Loop While node implementation](https://forum.dynamobim.com/t/loop-while-node-implementation/2507):
>
> Hi! I’m new at dynamo and i’m having a bit of trouble implementing the loop while node. I’ve looked up the forum for everything related to this node but still can’t get this to work. I’m trying to develop a function that imports text from a Revit General Annotation object, looks up the translation on a custom “dictionary” developed by the user (Excel file), and then writes back the translated text in another field of the Annotation. I’ve managed to get everything to work except the loop part.…

Well i cant upload something, cause im too new. Then i´ll try to write it down:  
Basic process:  
Rectangle.ByWidthLength - Polygon Corners - List.Flatten - List.Shuffle - List.First.Item  
Code Block with angles - List.Flatten - List.Shuffle - List.First.Item → Create Geometry!

Then i tried to combine it with this code from the example above:

```auto
def move_cubes_shift(cubes:var[]){
return = [Imperative]{
dist = 0.1..1..#Count(cubes);
for (i in GetKeys(cubes) )
{
    old = List.TakeItems(cubes,i+1);
    to_move = List.DropItems(cubes,i+1);
    moved = {};
    for (c in to_move)
    {
        c1 = c.Translate(Vector.XAxis(), dist[i]);
        moved = List.AddItemToEnd(c1, moved);
    }
    cubes = Flatten({old, moved});
}
return = cubes;
}};

```

Im grateful for every help i can get. Thanks in advance!  
DanielArch

---

<div class="post-metadata">

**Author:** ![DanielArch](https://avatars.discourse-cdn.com/v4/letter/d/e480ec/32.png) [@DanielArch](https://forum.dynamobim.com/u/DanielArch)\
**Post date:** [January 3, 2020, 11:20am UTC](https://forum.dynamobim.com/t/growing-structure-iteration-loopwhile-listmap/44894/2 "2020-01-03T11:20:51Z")

</div>

Still not getting behind. Probably gonna learn to design skript for this.
