From 8e34c1d7df4f88b5fc3bf323d72b82e5a880552b Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 16 May 2025 19:43:27 +0500 Subject: [PATCH] Fix error using bim.updating_representation for object with material set Possibly occurred after 4c255cc, but haven't investigated deeper. @BIMvoice The error you were reporting about Split Along Edge operator was caused by this issue, should be fixed now too. See https://jmp.sh/hgJEHsgH Example error traceback: ``` Error: Python: Traceback (most recent call last): File "C\bonsai\bim\ifc.py", line 487, in execute_ifc_operator result = getattr(operator, "_execute")(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C\bonsai\bim\module\geometry\operator.py", line 541, in _execute self.update_obj_mesh_representation(context, obj) File "C\bonsai\bim\module\geometry\operator.py", line 666, in update_obj_mesh_representation tool.Ifc.link(new_representation, data) File "C\bonsai\tool\ifc.py", line 230, in link IfcStore.link_element(element, obj) File "C\bonsai\bim\ifc.py", line 258, in link_element tool.Geometry.get_mesh_props(obj).ifc_definition_id = element.id() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C\bonsai\tool\geometry.py", line 92, in get_mesh_props return mesh.BIMMeshProperties ^^^^^^^^^^^^^^^^^^^^^^ ReferenceError: StructRNA of type Mesh has been removed ``` --- src/bonsai/bonsai/bim/module/geometry/operator.py | 1 + src/bonsai/bonsai/tool/material.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bonsai/bonsai/bim/module/geometry/operator.py b/src/bonsai/bonsai/bim/module/geometry/operator.py index 7042789adb..d739c57c49 100644 --- a/src/bonsai/bonsai/bim/module/geometry/operator.py +++ b/src/bonsai/bonsai/bim/module/geometry/operator.py @@ -589,6 +589,7 @@ class UpdateRepresentation(bpy.types.Operator, tool.Ifc.Operator): tool.Material.ensure_material_unassigned([element_type]) ifcopenshell.api.material.unassign_material(self.file, products=[product]) tool.Material.ensure_material_unassigned([product]) + data = obj.data # Required after ensure_material_unassigned else: # These objects are parametrically based on an axis and should not be modified as a mesh if extrusion := tool.Model.get_extrusion(old_representation): diff --git a/src/bonsai/bonsai/tool/material.py b/src/bonsai/bonsai/tool/material.py index 0139a1b783..dde9cc53d8 100644 --- a/src/bonsai/bonsai/tool/material.py +++ b/src/bonsai/bonsai/tool/material.py @@ -329,7 +329,10 @@ class Material(bonsai.core.tool.Material): or some other may be applied now since it's no longer overridden, therefore we need to make sure blender materials reflect correct styles. - Designed to be called after material.unassign_material API call.""" + Designed to be called after material.unassign_material API call. + + Will reload representations, invalidating existing object data. + """ elements = elements.copy() # Avoid argument mutation. for element in elements[:]: if element.is_a("IfcElementType"):