Looking to set Parameter value with Python. Am I using the correct command?

I have a list of elements, and I want to set the value of the “Item Number” parameter for each item in the list.

I will be using the Parameter “Comments” just for now to test it all out.

I’m trying to use the following code:

IN[0][0].SetParameterByName["Comments"] = "A"

but it gives me the following error:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 212, in
TypeError: ‘builtin_function_or_method’ object is unsubscriptable

I can successfully set the parameter using Dynamo nodes and even a Code Block, I’m just having difficulty translating that to Python.

Aaand I’ve found the problem. My code above is attempting to redefine the ‘Comments’ value from the dictionary “Parameters” and it cannot do that because it is built in. The correct code is below:

ELM.SetParameterByName("Comments", "A")


Can you share the full code for it?

Hi @dfgind

Here’s something to work with:


import clr

#Import the Revit API
import Autodesk
from Autodesk.Revit.DB import *

#Import DocumentManager and TransactionManager
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

#Reference the active Document and application
doc = DocumentManager.Instance.CurrentDBDocument

elem = UnwrapElement(IN[0])

elem_param = elem.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)

if elem_param.Set('Hello World'):
	OUT = 'Success'
	OUT = 'Failed to Set Parameter'

Link to the Set() method from the API.