Repeat command for n values

in order to get a housing unit tag with number and area I set up a dynamo script that is summing up the areas of all rooms with the same unit number and writes these values back in a shared parameter for rooms. This is working so far, but as I have more than 300 housing units I was wondering if there is a simple way to repeat the command for housing unit 0 - n. Ideally by using Dynamo nodes as I don’t have any scripting knowledge so far. Right now I would have to change the numbers and repeat the script depending on the number of units …


I do not really understand what your graph do (a lot of wires !), but one advantage of Dynamo over Grasshopper is that you can work with lists and manipulate them quite easily. Instead of creating as many nodes as objects to your lists, try to feed your entire list to the node you want, and evenetually work on lacing. The List.GetItemAtIndex nodes do not seem necessary if your are doing it for each element you have…

If you desperately need a loop function, there is a node : LoopWhile. There is also another wxay to do it : Force dynamo to rerun the node multiple times

Eventually, you can work on your list structure. You can for instance create a list that contains two lists : the list of your rooms and a list of parameters that go with each parameter, etc.

Hope this helps

1 Like

thanks for your answer. My problem is that I have to work stepwise. I cannot feed the last custom node with a whole list, as I want to get the sum per unit. I’m going to add the graph of the custom node, so you can see what it does …
I just copied the node so I can get the results for at least 10 units each time I run the script, that’s why there are so many wires in the first graph

I’ve been checking out the LoopWhile node, but I can’t figure out how I could make that work in my case.

Hi again,

Looking at your graph, I don’t understand why you have to work stepwise, why you should need a loop. The only time I needed a loop in a Dynamo graph (using just DesignScript and nodes) is when I needed to iterate on a single list which values changed at each iteration. Looking at what you provided, Is seems to me that all of your iteration are independant, thus, you should not need any king of loop.

If you are sure that your custom node is working fine, try it for a single iteration (it should not be called like that, a set of input may be more correct), then define correctly in your custom node the type of each input. In the last screenshot you gave, the type of each input is set to var[]…[], meaning that Dynamo does not care about the type. It would be wiser to set these to a correct value.

For instance, say you know how to apply your custom node on a set of input which type is (Element, int, Surface). In the definition of your custom node (the .dyf file), put each type to the corresponding input. Then, in your graph (.dyn file), if you feed your custom node with given input :

  • If the inputs are of type (Element, int, Surface), the node will work as intended
  • If the inputs are of type (Element[], int[], Surface[]) (i.e. a list of Element, a list of int, a list of Surface), the node will be applied to Element[0],int[0],Surface[0] then to Element[1],int[1],Surface[1], then to Element[2],int[2],Surface[2], and so on (which appear what you want to be doing)
  • If the input are of type (Element[], int[], Surface), the node will be applied to Element[0],int[0],Surface then to Element[1],int[1],Surface, and so on.

Maybe a totally misunderstood what you are asking, but it seemed to med that this should apply to you graph.

Hope it helps

An example of one of my custom nodes. I defined the custom node to be able to operate on a list of Surface and a list of Solid, however, in my graph, I am feeding it a List of list of Surface and a list of list of Solid.


thanks again, that sounds promising, I’m struggling though with applying your recommendations / examples. If I understand you right the solution would be to create lists of lists (in my case the housing units with the related rooms as sublists), so that the sums are created for the sublists only?
I’ll give this a try …

Here’s a simplified version of my graph without the custom node, in case anyone else has an idea of how to solve this without running the script more than 300 times and changing the number each time …

Exactly what I meant :slight_smile: As long as your input types are correctly defined, this should work correctly. However, without the custom node, it should be a little more complicated, but doable (just make sure you are dealing with the correct list level at each step).

it took me a while to get the lists matching but here’s the working result …