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
```
This commit is contained in:
Andrej730
2025-05-16 19:43:27 +05:00
parent 4369baa226
commit 8e34c1d7df
2 changed files with 5 additions and 1 deletions
@@ -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):
+4 -1
View File
@@ -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"):