Iterating through list


#1

I have a list of elements filtered by a parameter. I want to take all the elements that have matching parameters and assign a value to a different parameter. That part is easy enough. The issue I have is that the list will vary every time I run the script. So I want to create a loop to run until the list is empty. I will post a screen shot once I can get but maybe somebody can help me in the meantime. Thanks.


#2

Please send elements showing what you’ve tried and searched and illustrating what you aim so we can quickly understand what it’s all about. Thanks :slight_smile:


#3

Ok. The first screen shot is the custom node I created in order to get me the list in the second screen shot. Then I run that list through the rest of the script seen in screen shot 2. I want to take the rest of the list, filter again, then run though the last part of the script.


#4

I have this DesignScript Loop While reference in my bookmarks that could help to get started:
http://dynamobim.org/forums/topic/how-to-run-a-loop-on-a-dynamo-graph/
And also this example of LoopWhile using a custom node as a function:


But it don’t know (yet) if this could work in your case :slightly_smiling_face:
Edit: here is another good example:
http://dynamobim.com/forums/topic/loopwhile-for-a-variable-x-need-output-for-a-variable-y/


#5

That last post got me what I needed. Thanks.


#6

@coastguard09 List.GroupByKey might be worth exploring.
If I’ve properly understood, you most likely can avoid Loop While or/and a Custom node
Try replacing your custom node with these…


#7

It’s amazing how much simpler these scripts could be. Thanks very much. Now I need to get the last part to run on each list individually. Thanks. I’ll post when I get it, unless someone beats me to the punch.

I just increased my step amount to 1 and everything works beautifully. Thanks fellas.


#8

Hint: Start by changing lacing to Longest


#9

[/quote]
Hint: Start by changing lacing to Longest

I am going to attempt to explain this. When I switched the lacing to longest it assigns a unique number to each element in all the lists (or list of list? I’m new to all of this). When I leave it to shortest, it takes each list and assigns the same value to each element in one list, then moves to the next list and does the same thing, Which is what I want.

I didn’t realize that all I needed to do is plug in your solution and it would run through all the list. I was for sure it had to be more complicated than that.


#10

See if the below example helps …
Note that lacing on List.Count
The last node only serves to demonstrate that parameter values were applied. (Not required, otherwise)


#11

That will be useful in the future but what I have works for what I need.


I want my list to be numbered as seen in the above screen shot.


#12

@coastguard09 Please see solution in my topic List.count for list level 2