Repeat same script in smaller chunks

Hi all - sorry for the long post.
I am asking for general word of advice.

I understand the fundamentals of dynamo in regards to code block scripting, levels and lacing.

I haven’t invested time in playing with python and Revit API (Yet) - but i also think it might not be necessary for my type of problem.

THE PROBLEM:
I find that Dynamo gets very slow if the task gets very big - especially when connecting nodes that somehow involves Revit elements.
(Updating multiple parameters for 10000s of element instances or placing 10000s of elements by point, etc.)

If the final node that involves Revit manipulation is frozen or not present the exact same script can often do a complete run in matters of secounds.

Sometimes it feels unreasonably slow. (1h<run)
Other times it is not even possible to run “all” at once without causing a crash.

THE CURRENT WORKAROUND:
Therefor i sometimes prefer to devide the task in smaller chunks and run the same script multiple times by using the Dynamo player in order to get to the same result as running the whole script once.

This solution is usualy to somehow take the first “n” instances and then use a clever way to filter out the “n” instances from the previous run automatically when re-runing the script.
That way i only have to hit run, then wait, then run again, then wait again - repeat.

That way my list gets “n” shorter after each run and will eventually gets to 0 remaining instances in list.
At this point I am happy and I stop.

THE QUESTION:
Do you have any idea of a smarter way of repeating the script in smaller chunks?

Preferably something “automatic” that doesent require to sit and wait between multiple runs in dynamo player.

I’ve been trying to find useful information about loop / loop while etc. But i feel like i might be going in a wrong direction.

Any hints is much appreciated.

Thanks!

For loops in Python are great.
While loops are also useful.

Obviously I can’t really say more as I don’t know exactly what you’re trying to do.

a for loop can basically do:
for this list
x = do this thing to each item in the list.
if x meets condition Y then do one thing… or add it to a new list…
if it doesn’t meet condition Y do something else.
it keeps going until it’s gone right through your list.

A while loop is similar … it keeps looping while the condition isn’t met.

Dunno if that helps.

1 Like
  1. Ensure no bindings are slowing things down; more info on that here: Element Binding in Revit.

  2. Ensure you’re only ‘going to the well once’ so to speak. Each time you send/receive data to/from Revit you take a speed hit; doubly so when your data set is larger than your memory can handle.

  3. Reduce the number of items in memory by processing things more effectively; n items in 2 nodes has different impact on performance than 2*n items laced in on node.

  4. Compact a few nodes into custom nodes or a single ‘in-line’ design script statement (reducing the data which has to be pushed into memory)

  5. Utilize dictionaries instead of lists. This will require a good amount of rework via Design script, but can significantly decrease memory consumption as it’s one item of significant size instead of n items a small size which is easier for modern computers to work with.

3 Likes