Set Element Levels With Python

Hi All

I am working on a script that changes the levels of elements filtered by category.
I have tried severally to set the elements to a new level, but I get the error “The parameter is read-only.” The level parameter is not read-only because I have modified it using OOTB nodes. Is there something I am missing? See the python code below, and thanks for your help.

# Set the parameter values of the input elements.
TransactionManager.Instance.EnsureInTransaction(doc)

for element in elements:
    if element_category_name in level_categories or element_category_name in reference_level_categories:
        element.LookupParameter("Level").Set(UnwrapElement(constraint_change_inputs[0]).Id)
TransactionManager.Instance.TransactionTaskDone()