From 4b15535c9c3f14a5b561db8f41c04beaeb05d192 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 22 Mar 2024 16:53:25 +0500 Subject: [PATCH] Fix issue removing material set 1) core.remove_material_set were removing material set and calling material_tool.get_active_material_type() 2) material_tool.get_active_material_type() called MaterialsData which failed with the traceback below since props.materias[current_index] had ifc id that were just removed Traceback (most recent call last): File "\prop.py", line 96, in get_material_types MaterialsData.load() File "\data.py", line 43, in load "active_styles": cls.active_styles(), ^^^^^^^^^^^^^^^^^^^ File "\data.py", line 119, in active_styles material = tool.Ifc.get().by_id(material) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File \blenderbim\libs\site\packages\ifcopenshell\file.py", line 411, in by_id return self[id] ~~~~^^^^ File \blenderbim\libs\site\packages\ifcopenshell\file.py", line 396, in __getitem__ return entity_instance(self.wrapped_data.by_id(key), self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File \blenderbim\libs\site\packages\ifcopenshell\ifcopenshell_wrapper.py", line 4619, in by_id return _ifcopenshell_wrapper.file_by_id(self, id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: Instance # 66 not found File "\prop.py", line 94, in get_material_types WARN (bpy.rna): C:\Users\blender\git\blender-v410\blender.git\source\blender\python\intern\bpy_rna.cc:1366 pyrna_enum_to_py: current value '2' matches no enum in 'BIMMaterialProperties', '', 'material_type' --- src/blenderbim/blenderbim/bim/module/material/data.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/material/data.py b/src/blenderbim/blenderbim/bim/module/material/data.py index 8fdb424a8b..cfdf3a8058 100644 --- a/src/blenderbim/blenderbim/bim/module/material/data.py +++ b/src/blenderbim/blenderbim/bim/module/material/data.py @@ -117,9 +117,12 @@ class MaterialsData: if not material: return results - material = tool.Ifc.get().by_id(material) + material = tool.Ifc.get_entity_by_id(material) - if not material.is_a("IfcMaterial"): + # NOTE: it's possible that data will be refreshed during material removal + # (when it will try to fetch active material type and will reach for material_types) + # and props.materials[i].ifc_definition_id will contain already removed id + if not material or not material.is_a("IfcMaterial"): return results for definition in material.HasRepresentation: