Force dynamo to rerun the node multiple times

Hi everyone. Let’s say I have the script to create the circle which has 10*t diameter (t is the sequence from 1 to 100). Is there any loop condition node to make dynamo create totally 100 circles with different diameter value (because there are 100 values of parameter t).
Thank you.

Hi,
It’s difficult to answer precisely without seeing the context.

Thank you @Alban_de_Chasteigner but this is not what I am looking for. Creating circle with different diameter is just an example. I want to make a condition loop to run many nodes over and over again. For example, creating circle with different diameter and then extrude, rotate with a different angle (5*t degree)

I think Alban is right. We can manage most of the cases by simply feeding the sequence of nodes you want to iterate a list of items to work with (that’s what Alban did).

In case you want to iterate on a sigle value and feeding back the node sequence the result of the previous operation, you cant try something like this. (Note that for the case you described in your initial post, it is overkill)

1 Like

Hi @mellouze. Actually I don’t see the difference between your code and while loop node. Because the funct input just only allows one node to wire in. I want many nodes to rerun in the loop not only one.

You can add as many functions and initial values in input as you want, you just have to specify it when defining the loopNTimes function.

def loopNTimes(var1:var[]..[],var2:var[]..[],n:int,func1:Function,func2:Function,func3:Function){

	c = [Imperative]{
		i = 0;
		v1 = var1;
		v2 = var2;
		v3 = var2;
		while(i<n){
			v1 = __Apply(func1,v1);
			v2 = __Apply(func2,v2);
			v3 = __Apply(__Apply(func3,v3),v2);
			i = i+1;
		}
		return [v1,v2,v3];
	}
	return = c;
};

Hello @mellouze ,

With some googling I ended up here and tried your sollution. I’m trying to let my script run for every excel row entry and save the file with those settings. AKA:

Excel row 1 -> script -> save as -> Excel row 2 -> script -> … -> no data rows left

The number of data-rows is variable. I the case of 2 data rows (image) I end up with 2 files both based on the last data row.

Do you know a solution for my problem?

Hope you can help!! Regards, Rien.

Hi :slight_smile:

I have some difficulty understading what’s your problem/goal.
Could you please provide some more information, i.e. :

  • What is your input data ?
  • What is your desired output ?
  • What is the problem that you are encountering ?

Hello @mellouze ,

Thanks for the quick reply!

Input: Excel data file with 3 coloms
image

Script:
Changes global parameters, then saves files.

Desired output:
New Revit files based on the input. In this case 2 files with both different configurations:

  1. 4800_9600_38.rvt (configuration global parameters: 4800, 9600, 38)
  2. 5100_9900_39.rvt (configuration global parameters: 5100, 9900, 39)

Problem:
Both files are based on the last row from excel. The script doest not run by excel row. It first runs all the options in excel and stops at the last row (in this case 4800, 9600, 38). Then saves-as the document with this configuration multiple times (in this case 2).

Output now (wrong output):

  1. 4800_9600_38.rvt (configuration global parameters: 5100, 9900, 39)
  2. 5100_9900_39.rvt (configuration global parameters: 5100, 9900, 39)

Hope this gives enough details :smiley:

It is hard understanding what your script does without all the previews turned on :confused: But i’ll try my best !

Have you tried creating a custom node ? You could create one such as this one :

  • Input data : Name of the parameters you want to change + Value of those parameters
  • What the node does : Change the parameters then save the file

It should not be very hard to accomplish that step (you script already does it :wink: ).

Then, try feeding your custom node all the different names/values of the parameters and see if it solves your problem.

If not, you could try using my approach (the one with only one function), with the function being the custom node you created.

Hope this helps !

Hello @mellouze !

Sorry for the delayed reply.

I tried feeding a custom node in the function. Result shown below. It gives me some Null values and an Empty Dictionary (even with a simple +1 function). Can you see what i’m doing wrong?

def TestLoop2(var1:var[]..[],func1:Function){

c = [Imperative]{

Succes = {};

	for(x in var1){
		Succes[x] = __Apply(func1, x);

	}
	return Succes;
}
return = c;

};

Hello,

Two things :

  • First, it is hard helping you with what you provided because I have no idea what your custom nodes are doing.
  • Second, I don’t think that you need the method that I described earlier in this post to achieve what your are trying to do. From what you writed in TestLoop2, it looks like that you just want to iterate on all the items of a given list and apply func1 to each item only once, which is something that Dynamo already does very well on its own.

I recommend opening another thread to further discuss the problems you are encoutering with the script, I don’t think that it is related to the solution I provided. Sorry for that.

Hello,

I’m sorry, here is the custom node.

The problem when I use just nodes is Dynamo running everything from left to right. Therefor i’m hoping to get a custom node in a for-loop.

I need a variaton on the list.map function, that can apply any function (or functions) to a list. The reason for this is so that I can use a custom node to apply multiple functions to list[0], then repeat those functions for list[1], and so on.

In this example i’m trying to generate multiple .rvt roof models using global paramters for depth, width and angle. Each combination given should save a RVT file based on the input, then move on to the next index in the list. Output should be multiple Revit Files with all different configurations.

image

image

def TestLoop2(var1:var[]..[],func1:Function){

c = [Imperative]{

Succes = {};

	for(x in var1){
		Succes[x] = __Apply(func1, x);

	}
	return Succes;
}
return = c;

};

Ok, I think I get your point in using this method then :slight_smile:

First things that pop out of my mind :

  • Are you certain that you custom node alone (i.e. applied to only one set of parameters) works ? It might be helpful to ensure that the problem does not come from the custom nodes you created.
  • Have you tried replacing Succes = {}; by Succes = []; ?I think that might explain the “Empty Dictionnary” output

Also, I think you might want to replace the definition of TestLoop2. You should not write :

Succes[x] = __Apply(func1, x);

But :

Succes[i] = __Apply(func1, x);

Where i is the index of x in var1.

This is why you are getting so much null values in your screenshot.

Maybe you should write something like this ? (I’m a little bit rusty Dynamo-speaking)

def TestLoop2(var1:var[]..[],func1:Function){

c = [Imperative]{

Succes = [];

	for(i in 0..(List.Count(var1)-1)){
		Succes[i] = __Apply(func1, var1[i]);

	}
	return Succes;
}
return = c;

Thanks! Something works now :smiley: I’m getting multiple RVT files based on the name. Somehow it won’t change the Global Paramters yet. Below i’ve got the node with watchnodes in between. I used a Passthrough node to make sure the parameters are changed before the RVT file is being saved (a Null value from a GlobalParameter.SetValue is the ‘normal’ output).

You made my day @mellouze !

It is finally working with the set-up below. Will make some tweeks, but the base is there. Being able to loop while using Dynamo-Nodes within that loop!

Thanks a-lot for your wisdom and reply’s!


image

#loop #designscript #revit #looping #forloop

3 Likes

Glad that worked :slight_smile:

1 Like

@RienDigibase, I am trying to use your method for a similar but more complex task. I can’t figure out how the input and output (succes??) for your custom nodes look like. Is it possible to show your custom nodes?
Thank you for your great job on figuring out LoopWhile with complex algorithms and sharing it with us.

Hello Merita,

The custom nodes are based on one input-index. I hope the example below will make things clear! If not, don’t hesitate to ask.


2 Likes