pset.edit_pset - fix issue editing enum props without EnumerationReference #5707

Traceback
```
Error: Python: Traceback (most recent call last):
  File "\bonsai\bim\ifc.py", line 443, in execute_ifc_operator
    result = getattr(operator, "_execute")(context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "\bonsai\bim\module\pset\operator.py", line 126, in _execute
    ifcopenshell.api.run(
  File "\ifcopenshell\api\__init__.py", line 92, in run
    return usecase_function(ifc_file, should_run_listeners=should_run_listeners, **settings)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "\ifcopenshell\api\__init__.py", line 252, in wrapper
    result = usecase(*args, **settings)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "\ifcopenshell\api\pset\edit_pset.py", line 166, in edit_pset
    return usecase.execute()
           ^^^^^^^^^^^^^^^^^
  File "\ifcopenshell\api\pset\edit_pset.py", line 176, in execute
    existing_props = self.update_existing_properties()
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "\ifcopenshell\api\pset\edit_pset.py", line 225, in update_existing_properties
    prop = self.update_existing_prop_enum(prop)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "\ifcopenshell\api\pset\edit_pset.py", line 251, in update_existing_prop_enum
    primary_measure_type = prop.EnumerationReference.EnumerationValues[
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'EnumerationValues'
```
This commit is contained in:
Andrej730
2024-11-07 16:22:21 +05:00
parent b0cc2e30a9
commit fb081e3cf2
@@ -247,10 +247,15 @@ class Usecase:
if not value:
if self._try_purge(prop):
return
# Only need the first enum type since all enums are of the same type.
if reference := prop.EnumerationReference:
primary_measure_type = reference.EnumerationValues[0].is_a()
elif enum_values := prop.EnumerationValues:
primary_measure_type = enum_values[0].is_a()
else:
primary_measure_type = self.get_primary_measure_type(prop.Name, new_value=value[0])
assert primary_measure_type, f"Couldn't find primary measure type for the prop value: '{value[0]}'."
for val in value:
primary_measure_type = prop.EnumerationReference.EnumerationValues[
0
].is_a() # Only need the first enum type since all enums are of the same type
ifc_val = self.file.create_entity(primary_measure_type, val)
sel_vals.append(ifc_val)
prop.EnumerationValues = tuple(sel_vals) or None