Set parameter values by using Python

Hello everyone!,
I am trying to set the parameter values of all elements using python embedded in Dynamo.
I have a list of parameter value (p11) and a list of parameter name (Paramname). When I set the parameter values using .Set() by looping over the parameter value list (p11). only the last item of the parameter value is set to the item. Which means I am unable to loop the .Set().
I am a beginner in python scripting . Any help is appreciated

Home.dyn (53.9 KB)

The variable names are quite difficult to understand to be able to understand your problem. I don’t know if this is related to your problem, but I noticed that one of your functions is structured in a way that it will only run once:

def flatlist(p1): #flatten parameter list
	flat_list = []
	for sublist in p1:
		flat_list = [x for item in sublist for x in item]
   		return flat_list

You are using a return statement within your for loop, which will cause the function to exit prematurely. For example, if you have the following list of lists:

[[0, 0],
 [0, 1],
 [0, 2]]

Your function would return [0, 0]. You are also defining the variable flat_list twice–perhaps you meant to append each of the flattened lists to a different list?

Edit: The function actually expects an additional level of nesting. See comment further down.


I am unable to flatten the list! I get this error! Any solution??

I actually misinterpreted the function. Your function assumes the input is a list of lists of lists (2 levels of nesting). The error implies that one of the inner items is a float (number), not a list.

sublist_1 = [[0, 1],
             [2, 3],
             [4, 5]]
sublist_2 = [[6, 7],
             [8, 9],
             [0, 1]]
outer_list = [sublist_1, sublist_2]

The first ‘item’ in sublist_1 would be [0, 1], and then the first ‘x’ would be 0.

Running your function directly on either sublist_1 or sublist_2 would raise a TypeError.

1 Like

Why not just use the out of the box Element.SetParameterValueByName? It’d be a lot of effort to refinine oil into gasoline every time you wanted to drive your car.

1 Like

Thanks a lot for the solution.So I finally managed to remove the float error.


now I have two lists “outList” which contains the Revit parameters and “p11” with parameter value. When I use the .Set() the parameter value of the last item in the list p11 is set to all the elements. Why is the loop taking only the last item?

Hey thanks for the reply! You mean the node in dynamo?

Yes. This one: Dynamo Dictionary

Hey thanks for the suggestion ! Yes I can use the node, but i have a huge list of parameters and working with python will be more effective! What do you think?

1 Like

Yes, but in my experience you’re chasing diminishing returns as the speed difference is on the order of fractions of a millisecond for most 1:1 interactions when comparing Design Script, Dynamo Nodes, and Python. Even If your scope is enough for that small fraction to matter, Revit is going to run slower than all the rest by enough of a timeframe that it will be the determining factor for runtime. The math changes significantly when you switch to using multiple functions in one node, but node for node replacement of out of the box Dynamo for Revit nodes with a Python node is usually a fools errand.

1 Like

working with python will be more rewarding :slight_smile:

1 Like