I have a situation where I need to change a property to thousands of elements at a time. Recording the same step using hyperworks GUI I get a code that looks like this:
def run():
model = hm.Model()
elements_collection = hm.Collection(model, hm.FilterByEnumeration(ent.Element, ids=[3761243, 3762452]))
MCID = ent.System(model, 1519)
elements_collection.set_items('MCID', MCID)
collection = hm.Collection(model, hm.FilterByEnumeration(ent.Element, ids=[3761243, 3762452]))
model.attributeupdateintmark(collection=collection, identifier=3240, solver=1, status=2, behavior=0, value=1)
However, when I run that code in the python console it does not change the property.
Ii works in a loop doing:
def run():
for i in ids:
element = ent.Element(model, i)
MCID = ent.System(model, 1519)
element.MCID = MCID
But that is so extremely slow as to be unusable. At 0.9s per iteration, doing that for a 500k elements takes more than 5 days in a i9-9900k cpu.
What am I doing wrong with collection.set_items? it comes straight out of the macro recorder.