mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 20:02:30 +00:00
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:
@@ -856,7 +856,7 @@ class IfcImporter:
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
def load_existing_meshes(self) -> None:
|
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):
|
def merge_materials_by_colour(self):
|
||||||
cleaned_materials = {}
|
cleaned_materials = {}
|
||||||
@@ -1075,7 +1075,7 @@ class IfcImporter:
|
|||||||
# Mesh may already exists (e.g. during representation reimport)
|
# 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.
|
# 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)
|
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"
|
old_mesh.name = mesh_name + ".old"
|
||||||
mesh = bpy.data.meshes.new(mesh_name)
|
mesh = bpy.data.meshes.new(mesh_name)
|
||||||
|
|
||||||
|
|||||||
@@ -674,7 +674,7 @@ class Geometry(bonsai.core.tool.Geometry):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_representation_data(cls, representation: ifcopenshell.entity_instance) -> Union[bpy.types.Mesh, None]:
|
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
|
@classmethod
|
||||||
def get_representation_id(cls, representation: ifcopenshell.entity_instance) -> int:
|
def get_representation_id(cls, representation: ifcopenshell.entity_instance) -> int:
|
||||||
|
|||||||
Reference in New Issue
Block a user