Element.SetParameterByName error

image

I am trying to loop through a list which has come from an excel sheet, and get it to write new values back into the elements but i keep getting the error.

Exception: The parameter’s storage type is not a string.

Any help?

put the cell format in excel to “text”, to make sure its passed as strings

What that error is telling you is that the parameter is NOT a string. This means it is looking for an number or integer, maybe a Boolean or something else. Check the parameter type in Revit to see what it is, then get the value from Excel into that format.

The possible storage types are:

  • String
  • Integer
  • Double
  • ElementId

Even if you are able to determine the StorageType for each parameter, there are some other components of your code which will most likely raise additional exceptions.

For example, you declare the variable “i” outside of your loop, then use a variable by the same name in your for loop. At the end of your for loop, you have “i+1” which will raise a SyntaxError. You could first modify your code from line 17 and below to be the following:

values = IN[0]
elements = IN[1]
parameter = IN[2]

for i in range(len(values)):
    value = values[i]
    element = elements[i]
    Element.SetParameterByName(element, parameter, value)

OUT = 'done'

You can use the Parameter.StorageType node outside of your function to first determine the StorageType property of each of the parameters you will be writing to. Here is an example with a Floor:

StorageType.dyn (7.3 KB)

@bm481 Could you post all your relevant files (dyn, rvt, xls)

also this line doesn’t look right

Element.SetParameterByName(element, parameter, value)

it should be

element.SetParameterByName( IN[2] , value)

also look into using the following instead (much easier)

for element, value in zip (IN[0],IN[1]):
   element.SetParameterByName(IN[2], value)

Element.SetParameterByName is inherited from Revit.Elements which accepts 3 arguments:
The revit element
The name of the parameter
The new value of the parameter
In this case, Element is not actually an element, but just part of the Revit.Elements library.

A different variable name for the element should probably be chosen since Element.SetParameterByName is used just after the element variable is declared which does seem a bit confusing. +1 on the zip function, much cleaner and more pythonic

1 Like

@cgartland
Have you run the code? Your way doesn’t work for me. Curious to know how you made it work:

Yes, it works, although we are using two slightly different methods.

image

It is a bit clearer to use DesignScript as you did, although I used RevitNodes for my example to try to retain some of the code used by OP. Here is another example which just imports the Revit library instead of importing everything from Revit.Elements:

image

2 Likes