Safer BlendData access

To avoid issues like #6771 when we by accident find an ID data-block from linked .blend file.
This commit is contained in:
Andrej
2025-06-05 16:45:31 +05:00
parent 87265d052b
commit 0d39f8df28
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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: