From 3bee746f490a7f5b762764df1ba64923872120dd Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 24 Feb 2021 13:49:06 +1100 Subject: [PATCH] Optimise aggregate creation on large file imports --- .../blenderbim/bim/import_ifc.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/ifcblenderexport/blenderbim/bim/import_ifc.py b/src/ifcblenderexport/blenderbim/bim/import_ifc.py index dd9bf1d6bd..a7e221387e 100644 --- a/src/ifcblenderexport/blenderbim/bim/import_ifc.py +++ b/src/ifcblenderexport/blenderbim/bim/import_ifc.py @@ -1189,16 +1189,26 @@ class IfcImporter: obj = bpy.data.objects.new("{}/{}".format(element.is_a(), element.Name), None) self.link_element(element, obj) - self.place_object_in_spatial_tree(element, obj) + + container_collection = self.get_aggregate_collection(element) collection = bpy.data.collections.new(obj.name) - obj.users_collection[0].children.link(collection) - obj.users_collection[0].objects.unlink(obj) + container_collection.children.link(collection) collection.objects.link(obj) self.aggregates[element.GlobalId] = obj self.aggregate_collections[rel_aggregate.id()] = collection + def get_aggregate_collection(self, element): + if hasattr(element, "ContainedInStructure") and element.ContainedInStructure: + container = element.ContainedInStructure[0].RelatingStructure + elif hasattr(element, "Decomposes") and element.Decomposes: + container = element.Decomposes[0].RelatingObject + + if container.is_a("IfcSpace"): + return self.get_aggregate_collection(container) + return self.spatial_structure_elements[container.GlobalId]["blender"] + def create_openings_collection(self): self.opening_collection = bpy.data.collections.new("IfcOpeningElements") self.project["blender"].children.link(self.opening_collection)