Changing element's workset from python script

Hi everyone.
Revit 2019, Dynamo 2.0.3.8810.
Im trying to create python script for dynamo, that will change elements workset, but when i run my code in dynamo im getting error:
Traceback (most recent call last):
File string, line 43, in module
Exception: The parameter is read-only.

In the code im getting Id of specific workset, then creating list of elements and finally trying to change the workset for these elements.
My code:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit import DB
from Autodesk.Revit.DB import *

clr.AddReference("System")
import System
from System.Collections.Generic import List

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager as TM

doc = DocumentManager.Instance.CurrentDBDocument


workset_collector = FilteredWorksetCollector(doc)
ws = ''
for c in workset_collector:
	if c.Name == "10_Structure":
		ws = c.Id.IntegerValue

filter = DB.ElementMulticategoryFilter(
	List[DB.BuiltInCategory]([
		DB.BuiltInCategory.OST_Walls,
		DB.BuiltInCategory.OST_Floors,
		DB.BuiltInCategory.OST_GenericModel,
		DB.BuiltInCategory.OST_Stairs,
		DB.BuiltInCategory.OST_Columns,
		DB.BuiltInCategory.OST_StructuralColumns
	]),
	False
)

elements = DB.FilteredElementCollector(doc).OfClass(FamilyInstance).WherePasses(filter)
	

with Transaction(doc, 'Workset change') as t:
	t.Start()
	for element in elements:
		parameter = element.Parameter[BuiltInParameter.ELEM_PARTITION_PARAM]
		parameter.Set(ws)
	t.Commit()

OUT = elements

Is there a way to change “read-only parameter”?

UPD: It seems there is a problem with complex families like stairs.

Check to see if the Parameter is read only first. This can be complex families, groups, or even modeled in place families.

if parameter.IsReadOnly:
    #do something
else:
    parameter.Set(workset)

Thank you for your answer.
There was a problem with element collector in

elements = DB.FilteredElementCollector(doc).OfClass(FamilyInstance).WherePasses(filter)

OfClass(FamilyInstance) includes ElementType elements, for which workset parameter is read-only.
Solved it by collecting elements this way:

elements = FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType().ToElements()

The same error happend when trying to change workset of Detail Lines! Any Ideas?!