place structural items in collections for new project

This commit is contained in:
Jesusbill
2021-10-04 21:32:09 +02:00
parent df2a2edeea
commit a6d363c542
@@ -156,6 +156,11 @@ class AssignClass(bpy.types.Operator):
or product.is_a("IfcContext")
):
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")
elif product.is_a("IfcStructuralConnection"):
self.place_in_structural_items_collection(obj, context, structural_collection="Connections")
else:
self.assign_potential_spatial_container(obj)
context.view_layer.objects.active = obj
@@ -201,6 +206,25 @@ class AssignClass(bpy.types.Operator):
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]:
members = bpy.data.collections.new("Members")
connections = bpy.data.collections.new("Connections")
items = bpy.data.collections.new("StructuralItems")
items.children.link(members)
items.children.link(connections)
project.collection.children.link(items)
for coll in [c for c in project.children if "StructuralItems" in c.name]:
for collection in [c for c in coll.children if structural_collection in c.name]:
for user_collection in obj.users_collection:
user_collection.objects.unlink(obj)
collection.collection.objects.link(obj)
break
break
break
def assign_potential_spatial_container(self, obj):
for collection in obj.users_collection:
if "Ifc" not in collection.name or collection.name == obj.name: