Collector now unassigns from old ifc collections

This commit is contained in:
Dion Moult
2024-08-03 22:04:38 +10:00
parent c58672cc25
commit 7af5db7cd4
2 changed files with 14 additions and 2 deletions
+1 -1
View File
@@ -1261,7 +1261,7 @@ class IfcImporter:
def place_objects_in_collections(self) -> None:
for ifc_definition_id, obj in self.added_data.items():
if isinstance(obj, bpy.types.Object):
tool.Collector.assign(obj)
tool.Collector.assign(obj, should_clean_users_collection=False)
def is_curve_annotation(self, element: ifcopenshell.entity_instance) -> bool:
object_type = element.ObjectType
+13 -1
View File
@@ -25,8 +25,20 @@ from typing import Union
class Collector(blenderbim.core.tool.Collector):
@classmethod
def assign(cls, obj: bpy.types.Object) -> None:
def assign(cls, obj: bpy.types.Object, should_clean_users_collection=True) -> None:
"""Links an object to an appropriate Blender collection."""
if should_clean_users_collection:
for users_collection in obj.users_collection:
if obj.BIMObjectProperties.collection == users_collection:
continue
# Users are free to user extra collections for their own
# purposes except for the reserved keyword "Ifc" and
# "Collection" (which is the default collection that comes with
# a Blender session)
if "Ifc" in users_collection.name or users_collection.name == "Collection":
print('removing', users_collection, 'from', obj)
users_collection.objects.unlink(obj)
element = tool.Ifc.get_entity(obj)
if element.is_a("IfcGridAxis"):