From fb081e3cf2d3a7e7ea453796494e566128597232 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 7 Nov 2024 16:22:21 +0500 Subject: [PATCH] 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' ``` --- .../ifcopenshell/api/pset/edit_pset.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/pset/edit_pset.py b/src/ifcopenshell-python/ifcopenshell/api/pset/edit_pset.py index d93bb9ebb9..c8c11e9695 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/pset/edit_pset.py +++ b/src/ifcopenshell-python/ifcopenshell/api/pset/edit_pset.py @@ -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