Repeat Function - Loop, repeat, cycle @ index?

hi all,

Is there a way for Dynamo to do a function at index 0, then move onto index 1 and repeat etc ? I had considered a loop but that returned errors.

Context

The graph in question is creating elevation markers (using a Room location) and then creating 4 elevation views on that marker. (List A)
The Room’s are filtered (or selected) by extracting the room number from the Sheet Name parameter. (List B)

As such, I’m retaining the index relationship between List A and List B. As the viable in List B is used to renamed the elevations in List A.

At present my working graph is a group of nodes that achieve the renaming operation that i have then copy and pasted numerous times changing the index filter number from 0 through to 15. So it works alright but its not the prettiest.

Any ideas?
(I’m pretty new at Dynamo so feel free to hit me with the obvious. haha.)

Thanks in advance for your input.

Ben

Hi,

Maybe something like shown in this post could help you or give you any idea.

hi Mellouze,

Your link does certain look like what I’m after, but if i’m understanding correctly, the issue wasn’t resolved in the way of finding a way to change an index number but was to change the way the graph filtered data by using the Sort.By.Key node.

However the link has pointed me towards the notion of “LoopNTimes”, which will require code as there doesn’t appear to be a Node as far as i’m aware. Issue is working out how to make my index value “i” and get my nodes above to plug into ‘function’ and check “i” is greater than “n” to return the loop.

Will this sort of thing work do you think?

Will let you know how i get along as I should have some time tomorrow to experiment. :+1:

Thanks,

Ben

You don’t really need a loop. You just need to manage your data in a way that everything will run together. Dynamo automatically “loops” if you provide the right inputs. Try looking into List Levels, lacing, and managing multiple sublists. If you have trouble getting list levels or lacing to work out properly you can always get rid of them completely. As long as every function has the same number of inputs Dynamo will “loop” through any list.

1 Like

@Nick_Boyts is right : generally speaking, you do not need loops in Dynamo. The only exception I have encoutered so far was the case where the ouput of each step heavely depended on the output of the previous step.
Generally speaking, you don’t need on Dynamo to do such things. You generally want to do the same operations/the same steps/apply the same nodes to a series of items : in that case list and data management is really handy.

Have you seen this already ? It explains really well how to replace repetitive actions on simple lists (which really looks like your problem) by simple actions on complex lists (thus gaining some time andgraph clarity).
http://primer.dynamobim.org/en/06_Designing-with-Lists/6-4_n-dimensional-lists.html

hi @mellouze & @Nick_Boyts

Thank you for your input. Funnily enough when you said “the same nodes to a series of items” it hadn’t occur to me to run both lists through the process (so not pulling a specific index). When i did that I then had a issue where 16 out of the 20 values in the graph were reaching the second String Replace (no idea why) however when i switched the lacing from Auto to Longest in that node, 20 values made it through.

The second String.Replace node also failed to rename the strings as intended. It did the operation 4 times, but only changed one string in each list. So to get around that I just broke the second String.Replace into 4 and had one for A, B, C and then D. [See Image below]

Not the prettiest ending but I learnt something new and the graph is both a lot shorter/smaller than before and won’t fail if the number of inputs exceeds the number of indexes I bothered to copy and paste :smile: Result!

Thanks again for the help.

Best,

Ben

1 Like

Glad you figure this out :slight_smile:

What you just used is probably the most important feature in Dynamo in my opinion !