Node to send items in a list one by one

I often come across this situation where I write a script successfully and then realize that it only works for individual elements and needs a lot changes for processing a list of items.

Is there any node that can process the first item on a list wait for the code to run completely and then pass the second index.?

Something like “Tool.run me” Except that I want it to automatically pass the second index as I may not be always sure of how many items the list gonna hold.

To be specific i made this following script to - read the elements in a room and adjust the room tags location to avoid overlaps

I made this for a single tag but, Now i want it to work for multiple tags.

sorry couldn’t upload any image here but, here is the link to image

TAGS OVERLAP.dyn (77.9 KB)

There’s the list map node which I think is supposed to do exactly that.
Your actual code is a bit, well, overwhelming to tackle. I’m not even sure where exactly your problem is there.
It basically works like this.


Give the input you’d generally put in the node of the specific function you want into the list.map list input and the function can go into the f(x) input, and you can leave the input you’d wanted to put into that node empty.
As you might see as well: every list.map goes one dimension “deeper”.

I opened your file but it seems too messy for me, plus I do not have some nodes (I advise you to use groups to organiza your nodes: right clicking on a set of nodes and “create group” option)

A quick way to make something work for many items would be to create a custom node: instead of “select model element” you can set an input (input node), so that when you load that custom node in a dyn file you can feed it all the elements you want and dynamo will try to make it work. (Since you have already written your script I advise you to try this method first, hopefully it should be quicker)

A better way in my opinion is to work right from the beginning with lists and using list levels (similar to list map) : link
To test it at the beginning you could simpy insert your single selected item in a list (eg. List Create node) and build the script from there, so that once you feed it more items it should still work.

2 Likes

The List level is already the third thing today I found out about Dynamo, and I’ve been using it for months.

@PauLtus s Helping others is the best way to learn :grinning:

Totally agree…! At the beginning i was so doubt full if I could achieve what i wanted,that y I dint keep them tidy and organized…! any ways I shall do them Once i start agin

thank you for the comments guys, In a nut shell this is what i am looking for

The correct approach here is to use list lacing or list levels, as others have mentioned, in order to get your graph to run with a list of inputs.

This is maybe the most important part of learning Dynamo - how to make your graph work with complex list structures. This will be good practice. It does mean going back through your graph and reworking nodes but that’s common practice. When I begin working on complex graphs, I always start out by making things function for a single element (this is the easiest way to troubleshoot) then go back and make things work on a list once I have my functionality worked out.

1 Like

The method @Nick_Boyts is proposing here is a good one.
Occasionally you can just run a list of items instead of one item and it might work, but that’s quite unlikely.
Fooling around with a couple of List.Map nodes will help, but that can still be difficult and the situation might occur that you’d have to add one for about every single node.
What is kinda clunky, but does very reliably work, is picking the entire bit of code you want to run a list through instead of an item, save that bit as a custom node, and let that run through a List.Map node. The only downside is that changing a bit of the code is a bit more work.
Hope it will help!

1 Like

Making a custom node is a quick and easy way to make something work on a list of inputs, but I would discourage you from using that method often. It’s also just good practice (I would even say necessary) to make your graphs and nodes work with list inputs.

The main point of a custom node should be to make a single task more easily available, not to combine an entire graph into a single node. (Keep in mind that there’s a good chance your graph already contains nodes that are working properly with list inputs, if you convert everything to a custom node these inputs may stop functioning as lists when you need them to. You basically create a new problem opposite to the one you’re trying to solve.)

I do agree. I think getting the hang of the List.Map node is the big trick here, but when you created a script that works fine for singular numbers but doesn’t work for a list, changing it to a point where it does can be quite a lot of trouble, but often simply doing everything properly structured will make the big difference. There’s tons of nodes which are very flexible with list inputs anyway.

1 Like

Thnks to everyone it finally worked after i started it from scratch,sorry for the delayed reply,

multi-tag overlaps.dyn (81.1 KB)

1 Like

Good to hear you got it figured out!
I did look at your script but to be honest it’s a bit too much for me to really comment on it as it’s quite a lot, but as you created it and know how it works you got a lot further than if some people just would’ve showed you a method that you didn’t actually understand.

You can mark your own comment as solution so people can see your problem is solved. :wink:

@PauLtus you are right…! and i am happy that i figured it myself but iam not marking the solution yet because Some one might create a custom node (to send items in a list one by one) someday to work for this situation as asked in this question.Hope this is OK…!

Sure.
You are actually very right as your problem might be solved but not the specific issue you made the topic about.

It seems that this custom node about running the function on the next item of list was never constructed. I do not have an idea how would that be. Can anyone provide an idea or a reference?