Apply a function to each item in a list before continuing to the next

Hello, I’m trying to iterate though a list and apply a function to each element in the list before continuing to the next item. See image below for what what I currently have. This part of the graph uses the Orchid and Clockwork packages.

I’m trying to loop though a list of families and open each one for editing, purge the file of unused elements, load it back into the current project, then close the file. The issue I’m having is if I just use the loopBody string of notes on their own without some kind of loop control, I run out of RAM because Revit/Dynamo is trying to open all the families at once which there are 692 of. I also just want to commit the changes to the project because the next element might be affected by the previous elements changes. I need some way to open one at a time, do the function, and then close and release it from memory before moving to the next family.

I thought using a LoopWhile or List.Map node would do the trick, but I can’t get either to work. I also tried to make the nodes a custom node in hopes that custom nodes inherently work on each item in a list one at a time instead of all at once, but that didn’t work either. Could someone help me out here?

Thanks.

Take a look at things like the BVN Batch processor or the Multiplayer addin from Bird Tools. They will handle the opening/saving/closing for you. Then you only need to make a graph for the actions you want to do within a file.

They look like they could help, but I’ll need to keep looking into them. I need to be able to run this in a project environment because I need to load the families back into a project before continuing onto the next family.

So I think I got something to work. I retried to use a custom node linked up to a loopwhile node and got it to work this time. Its still not a perfect solution because my RAM still fills completely up when running, but at least it finished this time. I even got a new warning message from Revit saying that Revit is using more memory than what’s on my system. It looks like my issue is really with the Orchid node to close the family file. It (or Revit) is still holding the family file in memory even though the file is closed. From what I found, the only way to release the memory is to somehow use python and use a ‘flush memory’ command or closing Revit.

Instead of working in the project environment, save the families as a library (in Revit), batch process the files, and then load them all back into the project.

Added benefit is that this is leveraging processes which likely should be in your maintenance and management efforts (saving out the family library) and enabling reuse of content.

1 Like

I would say Birdtool…https://www.birdtools-developers.com/ think its more stable then background open nodes,

1 Like

I could do it this way, I already save out the family library into individual files. The only issue with doing it this way for this task is I would need to re-do it about 2 or 3 times to get the result i’m looking for. Because loading the family back into the project could affect the next family because it’s nested in it.

Would you still use Dynamo to batch process the files? Wouldn’t that still hold the file in memory until Revit is closed leading back to the same issue?

I’d likely use the BirdTools item noted above, and write the graph to do one thing at a time.