Looping through list items

Looping through list items

Anonymous
Not applicable
5,409 Views
2 Replies
Message 1 of 3

Looping through list items

Anonymous
Not applicable

Hi all,

My problem is quite simple in nature, yet difficult to accomplish.

 

I have a list of 3 spaces as shown below, that are selected from active view. I would like to be able to select each single space in the list starting from index 0 alone by itself to perform some processing on it, the item selection has to progress one item at a time - if successful with these 3 spaces the script will be scaled up to include 200 spaces.

 

I have tried to iterate through this list using a Python script, but the script will always output a list again because I am using list.append() method to get the output, it's really important to get one space at a time automatically, and not generate a new list.

 

Using filter by bool mask is not going to work for this exercise, as there are certain aspects of the calculations done on each space that requires supplying each space individually one at a time.

 

Any help in this matter will be greatly appreciated. I am using Revit 2020. @jeremytammik 

 

Dynamo Graph:

Dynamo GraphDynamo Graph

 

 

 

 

 

 

 

 

 

 

mickeysemf_1-1609411217338.png

 

 

0 Likes
Accepted solutions (2)
5,410 Views
2 Replies
Replies (2)
Message 2 of 3

RPTHOMAS108
Mentor
Mentor
Accepted solution

Not sure if you want to index the rooms collection in the graph or do something in the Python code between the lines

 

'for item in inputlist:"

&

"     outputlist.append(item)"

 

I found with Dynamo that it runs the graph, stores the state and then doesn't re-run parts of it unless state changes. This makes manual looping within the graph structure itself hard. I think the idea is that you arrange the graph as if it were a single item and then by the features of Dynamo it does the same thing to a list of items (based on conditions of the graph for each item). So you can loop through each item in Python and do something within that node, which is probably the best option. I caveat all of the above with the statement that I'm not a Dynamo expert and the people that are spend more time at: Dynamo (dynamobim.com)

 

 

0 Likes
Message 3 of 3

Anonymous
Not applicable
Accepted solution

I had a go at it this way, after many attempts I was able to get to a solution without having to loop through each element as I described above, the problem was that I had sublists within lists and I needed to process them using a list without any sublists.

 

The idea behind the script was taking air flow values from over 1000 spaces, checking how many air terminals each space has, divide the value of air flow over number of grilles in each space, then assign the new air flow value to each grille.

 

The solution was to change the level of the list to match that of the sublist and it worked. I was hoping to find a solution in Python that maybe I am not aware of, but it seems that I can only use an iterable data type as an output or input.

 

mkshehata_0-1609430766508.png

 

I have attached the dymamo file for anyone interested in accomplishing a similar task I have tested it on a small project with few spaces and was successful.

 

Thanks