LOOP - Introduce multiple parameters to an instance element

Hi all,

I’m trying to introduce multiple parameters to one instance family. As I show in the image below it is working, but I would like to optimice the code with a loop or similar, as for each node the only thing changing is the index i am taking from each list. For the moment there are just 9 parameters now, so it is not much work, but I would like to increase significantly the number of parameters to introduce and that would help.

Thanks in advance!


I guess something like this could get you started.


	result = element;
	for(i in 0..List.Count(params)-1){
		result = Element.SetParameterByName(result,params[i],values[i]);
	return = result;

Thanks @mellouze

I tried it and for some reason Dynamo is not understanding the inputs List.Count and Element.SetParameterByName. It gives me this error:

Warning: Variable ‘List’ hasn’t been defined yet
Variable ‘Element’ hasn’t been defined yet

Do u know how i can fix this?



Thanks @Jonathan.Olesen now it is working.
Is there a rule/list to know this changes when writting in code blocks

They are caused by custom packages using the same namespace as the OOTB ones :slight_smile: if written as a single line in a code block it will list the possibilities in the error :slight_smile:

fyi I moved the solution to @mellouze as he solved the initial topic problem :slight_smile:

what for multiple elements, how do you another level of loop for elements???


Short and lazy way : create a custom node and feed it a list of elements as one of its inputs.

However, I would recommend re-writing the code from scratch to adapt it to your needs.

I am just a bit confused about the return of for loop, I don’t know any python or javascript.
Anyway, I did a 2 dimension loop, The logic seems ok. And it’s somehow fonctionnal, even though very very very long.

I agree that it is a bit confusing at first, but that’s how DesignScript works. It allows you to store values computed in the imperative block outside of said block.

It is indeed long because that is in no way an optimised way of achieving this specific goal, rather an “ad hoc” solution… There must be a better thing to do, maybe through Python, using a custom node, using specific lacing, etc.

Can you please help me to get it work with multiple elements?

Hi, doesn’t this post help you figuring it out ? It seems correct to me.

1 Like

I tried this also. But didnt work

Could you show your attempt and explain why you think it is not working ? I have answered this post nearly a year back now

Thanks, it worked.

Though it gives me no warning or error. But the value doesn’t seem to set in the Revit as you can see in the attached picture.

Can you please help me out?