From 0d39f8df282777180847d8a28158feb14ef25a29 Mon Sep 17 00:00:00 2001 From: Andrej Date: Thu, 5 Jun 2025 16:45:31 +0500 Subject: [PATCH] Safer BlendData access To avoid issues like #6771 when we by accident find an ID data-block from linked .blend file. --- src/bonsai/bonsai/bim/import_ifc.py | 4 ++-- src/bonsai/bonsai/tool/geometry.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bonsai/bonsai/bim/import_ifc.py b/src/bonsai/bonsai/bim/import_ifc.py index 1332258c12..47d0157b6b 100644 --- a/src/bonsai/bonsai/bim/import_ifc.py +++ b/src/bonsai/bonsai/bim/import_ifc.py @@ -856,7 +856,7 @@ class IfcImporter: return obj def load_existing_meshes(self) -> None: - self.meshes.update({m.name: m for m in bpy.data.meshes}) + self.meshes.update({m.name: m for m in bpy.data.meshes if m.library is None}) def merge_materials_by_colour(self): cleaned_materials = {} @@ -1075,7 +1075,7 @@ class IfcImporter: # Mesh may already exists (e.g. during representation reimport) # and we assign some suffix to it to prevent Blender from adding '.001' suffix to the new mesh. mesh_name = tool.Loader.get_mesh_name_from_shape(geometry) - if old_mesh := bpy.data.meshes.get(mesh_name): + if old_mesh := bpy.data.meshes.get((mesh_name, None)): old_mesh.name = mesh_name + ".old" mesh = bpy.data.meshes.new(mesh_name) diff --git a/src/bonsai/bonsai/tool/geometry.py b/src/bonsai/bonsai/tool/geometry.py index 31349d36ba..d28ddb97b0 100644 --- a/src/bonsai/bonsai/tool/geometry.py +++ b/src/bonsai/bonsai/tool/geometry.py @@ -674,7 +674,7 @@ class Geometry(bonsai.core.tool.Geometry): @classmethod def get_representation_data(cls, representation: ifcopenshell.entity_instance) -> Union[bpy.types.Mesh, None]: - return bpy.data.meshes.get(cls.get_representation_name(representation)) + return bpy.data.meshes.get((cls.get_representation_name(representation), None)) @classmethod def get_representation_id(cls, representation: ifcopenshell.entity_instance) -> int: