Parameters read-only after ungrouping

I need to push some new parameters through existing groups, and since there’s no way to do that through the API I’m ungrouping, pushing the parameters, regrouping, switching all instances of the original group to the new one, and then renaming the new one to match the old one.

However whenever I try to run my code, I get an error stating that “The Parameter is read-only.” I know these are not read-only parameters, so it presumably has something to do with the fact that the elements were in a group previously.
I thought putting them in two transactions would work, but no such luck.

My code is below, but I swapped out the parameters for built-in ones.

TransactionManager.Instance.ForceCloseTransaction()

ungroup_ta = Transaction(doc)
ungroup_ta.Start("Ungroup")

orig_name = orig_group.Name

elems = orig_group.UngroupMembers()
ungroup_ta.Commit()

update_ta = Transaction(doc)
update_ta.Start("Update Parameters")

for e in elems:
    el = doc.GetElement(e)
    el.LookupParameter("Comments").Set(IN[2])
    el.LookupParameter("Sector").Set(IN[3])
    el.LookupParameter("Mark").Set(IN[4])

new_group = doc.Create.NewGroup(elems)
new_type = new_group.GroupType
new_type.Name = orig_name + " Copy"

col = FilteredElementCollector(doc).OfClass(Group).WhereElementIsNotElementType().ToElements()
existing = [x for x in col if x.Name == orig_name]

for group in existing:
    group.GroupType = new_type

update_ta.Commit()

Any ideas?

I guess I should mention I did try using Dynamo’s transaction manager before force closing it and making a couple transactions myself.

I would look at using sub transactions and wrapping the parameter setting up in one as well with commit before trying to group them again. It shouldn’t affect it, but if you remove the regrouping, does it work?

Wrapping the parameter update in a subtransaction, under the ungroup transaction, as well as removing the regrouping section didn’t seem to do anything.

TransactionManager.Instance.ForceCloseTransaction()
ungroup_ta = Transaction(doc)
ungroup_ta.Start("Ungroup")

orig_name = orig_group.Name
elems = orig_group.UngroupMembers()

sb = SubTransaction(doc)
sb.Start()
for e in elems:
    el = doc.GetElement(e)
    el.LookupParameter("Comments").Set(IN[2])
    el.LookupParameter("Sector").Set(IN[3])
    el.LookupParameter("Mark").Set(IN[4])
sb.Commit()

ungroup_ta.Commit()

Have you verified that ALL elements within the group are items that have these parameters available? What if you just grab a single element from the elems[0] and set a single parameter on it?

I thought I had tested all the parameters individually but apparently not. Sector seems to be read-only, however, I found something else interesting when troubleshooting.
I’m using a small 3 element group, and turns out if I do one at a time by manually changing what index it grabs it updates all 3 parameters on that one object - Including Sector.

So I can update Sector outside of the loop, but not inside.

1 Like

Have you tried to see if there is a 4th [3] element in the list? I know you only have 3 items, but may be worth trying. You could also change it to a range loop and see if it will iterate them like your doing manually.

1 Like

Have you tried to see if there is a 4th [3] element in the list?

image

I guess that would do it, huh? Haha

It’s always the simple things you forget to check. Thanks!

Edit:
For those curious, the extra elements are center lines.
image

1 Like

There is almost always more than meets the eye.