From 04209c78b9cd6eafaa1a4940923fdf4f15924d12 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 14 Oct 2021 13:06:26 +1100 Subject: [PATCH] Minor revert - until I properly refactor and test this. --- .../blenderbim/bim/module/root/operator.py | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/blenderbim/blenderbim/bim/module/root/operator.py b/src/blenderbim/blenderbim/bim/module/root/operator.py index d3ae96aaad..4d2e77f91f 100644 --- a/src/blenderbim/blenderbim/bim/module/root/operator.py +++ b/src/blenderbim/blenderbim/bim/module/root/operator.py @@ -157,7 +157,7 @@ class AssignClass(bpy.types.Operator): or product.is_a("IfcProject") or product.is_a("IfcContext") ): - tool.Collector.assign(obj) + self.place_in_spatial_collection(obj, context) elif product.is_a("IfcStructuralItem"): if product.is_a("IfcStructuralMember"): self.place_in_structural_items_collection(obj, context, structural_collection="Members") @@ -191,6 +191,29 @@ class AssignClass(bpy.types.Operator): break break + def place_in_spatial_collection(self, obj, context): + for collection in obj.users_collection: + if collection.name == obj.name: + return + parent_collection = None + for collection in obj.users_collection: + collection.objects.unlink(obj) + if "Ifc" in collection.name: + parent_collection = collection + collection = bpy.data.collections.new(obj.name) + collection.objects.link(obj) + if parent_collection: + parent_collection.children.link(collection) + blenderbim.core.aggregate.assign_object( + tool.Ifc, + tool.Aggregator, + tool.Collector, + relating_obj=bpy.data.objects.get(parent_collection.name), + related_obj=obj, + ) + else: + context.scene.collection.children.link(collection) + def place_in_structural_items_collection(self, obj, context, structural_collection): for project in [c for c in context.view_layer.layer_collection.children if "IfcProject" in c.name]: if not [c for c in project.children if "StructuralItems" in c.name]: