Fix #4649. Bug where editing property set template enumerations didn't clean up properly.

This commit is contained in:
Dion Moult
2024-05-11 15:18:18 +10:00
parent 6df6553935
commit cd2570cdbb
5 changed files with 107 additions and 30 deletions
@@ -47,7 +47,20 @@ def edit_prop_template(
ifcopenshell.api.run("pset_template.edit_prop_template", model,
prop_template=prop, attributes={"Name": "DemoA", "PrimaryMeasureType": "IfcLengthMeasure"})
"""
settings = {"prop_template": prop_template, "attributes": attributes}
if enum_values := attributes.get("Enumerators", None):
prop_name = attributes.get("Name", None) or getattr(prop_template, "Name", None) or "Unnamed"
primary_measure_type = (
attributes.get("PrimaryMeasureType", None) or getattr(prop_template, "PrimaryMeasureType", None) or "IfcLabel"
)
enum_values = [file.create_entity(primary_measure_type, v) for v in enum_values]
if enumerators := prop_template.Enumerators:
enumerators.Name = prop_name
enumerators.EnumerationValues = enum_values
else:
prop_template.Enumerators = file.create_entity("IfcPropertyEnumeration", prop_name, enum_values)
for name, value in settings["attributes"].items():
setattr(settings["prop_template"], name, value)
if "Enumerators" in attributes:
del attributes["Enumerators"]
for name, value in attributes.items():
setattr(prop_template, name, value)