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")

6 Likes

Can you share the full code for it?

Hi @dfgind

Here’s something to work with:

Python:

import clr

#Import the Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

#Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
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)

TransactionManager.Instance.EnsureInTransaction(doc)
if elem_param.Set('Hello World'):
	OUT = 'Success'
else:
	OUT = 'Failed to Set Parameter'
TransactionManager.Instance.TransactionTaskDone()

Link to the Set() method from the API.

5 Likes