When I try to set the level for Duct fitting or pipe fitting using python, I'm getting a error saying the parameter is read only, can someone help me with this

Kindly see the below snip for more info.

Python Script:

elements = UnwrapElement(IN[0])
Level  = UnwrapElement(IN[1])
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for element in elements:
	Param = element.LookupParameter("Level")
	SetValue = Param.Set(Level.Id)


TransactionManager.Instance.TransactionTaskDone()

OUT = element

Error I got “IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 47, in
Exception: The parameter is read-only.”

The LookupParameter() method returns the first match it finds. In this case, DuctFitting elements actually have two “Level” parameters. The first one is the schedule level, which is read-only, and the second is the associated level that you’re looking for.

To get the specific parameter that you’re after, you can use the BuiltInParameter method instead.
element.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM)

If you use the standard Dynamo nodes this would get handled automatically.

I know dynamo nodes gives better result but I’m working on a bigger script in which this was the small portion where I got the error, so I have just concentrate on the error to get the answer. Thanks anyway, I didn’t know this. If you can explain how to set the this BuiltInParameter.FAMILY_LEVEL_PARAM with different Element Id it would be helpful.

Thanks

The issue was that you were collecting the wrong parameter. That line will get you the correct parameter that you can then write to like any other parameter.

It is working thanks