aggregate.assign_object - support batching #4474

This commit is contained in:
Andrej730
2024-04-08 16:23:48 +05:00
parent d764c0af23
commit cd11d2de27
34 changed files with 187 additions and 143 deletions
@@ -73,7 +73,7 @@ class Usecase:
as IfcBuilding, IfcBuildingStorey, or IfcSpace that the element
exists in.
:return: The IfcRelContainedInSpatialStructure relationship instance
or `None` if nothing was changed.
or `None` if `products` was empty list.
:rtype: Union[ifcopenshell.entity_instance.entity_instance, None]
Example:
@@ -128,13 +128,17 @@ class Usecase:
products_without_containers.append(product)
continue
# either structure_rel is None or product is part of different rel
if product_rel != structure_rel:
previous_containers_rels.add(product_rel)
products_with_containers.append(product)
# products with already assigned containers will be skipped
products_to_change = products_without_containers + products_with_containers
# nothing to change
if not products_without_containers and not products_with_containers:
return
if not products_to_change:
return structure_rel
# can be either only aggregated or only contained at the same time
for product in products_without_containers:
@@ -142,7 +146,7 @@ class Usecase:
if aggregate:
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=product)
# unassign elements from previous container
# unassign elements from previous containers
for rel in previous_containers_rels:
related_elements = set(rel.RelatedElements) - products
if related_elements:
@@ -170,7 +174,7 @@ class Usecase:
)
# localize placement relative to a new container for affected products
for product in products_without_containers + products_with_containers:
for product in products_to_change:
placement = getattr(product, "ObjectPlacement", None)
if placement and placement.is_a("IfcLocalPlacement"):
ifcopenshell.api.run(
@@ -45,12 +45,12 @@ class Usecase:
storey3 = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuildingStorey")
# The project contains a site (note that project aggregation is a special case in IFC)
ifcopenshell.api.run("aggregate.assign_object", model, product=site, relating_object=project)
ifcopenshell.api.run("aggregate.assign_object", model, products=[site], relating_object=project)
# The site has a building, the building has a storey, and the storey has a space
ifcopenshell.api.run("aggregate.assign_object", model, product=building, relating_object=site)
ifcopenshell.api.run("aggregate.assign_object", model, product=storey, relating_object=building)
ifcopenshell.api.run("aggregate.assign_object", model, product=space, relating_object=storey)
ifcopenshell.api.run("aggregate.assign_object", model, products=[building], relating_object=site)
ifcopenshell.api.run("aggregate.assign_object", model, products=[storey], relating_object=building)
ifcopenshell.api.run("aggregate.assign_object", model, products=[space], relating_object=storey)
# Create a column, this column spans 3 storeys
column = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
@@ -59,12 +59,12 @@ class Usecase:
storey3 = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuildingStorey")
# The project contains a site (note that project aggregation is a special case in IFC)
ifcopenshell.api.run("aggregate.assign_object", model, product=site, relating_object=project)
ifcopenshell.api.run("aggregate.assign_object", model, products=[site], relating_object=project)
# The site has a building, the building has a storey, and the storey has a space
ifcopenshell.api.run("aggregate.assign_object", model, product=building, relating_object=site)
ifcopenshell.api.run("aggregate.assign_object", model, product=storey, relating_object=building)
ifcopenshell.api.run("aggregate.assign_object", model, product=space, relating_object=storey)
ifcopenshell.api.run("aggregate.assign_object", model, products=[building], relating_object=site)
ifcopenshell.api.run("aggregate.assign_object", model, products=[storey], relating_object=building)
ifcopenshell.api.run("aggregate.assign_object", model, products=[space], relating_object=storey)
# Create a column, this column spans 3 storeys
column = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
@@ -42,11 +42,11 @@ class Usecase:
storey = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuildingStorey")
# The project contains a site (note that project aggregation is a special case in IFC)
ifcopenshell.api.run("aggregate.assign_object", model, product=site, relating_object=project)
ifcopenshell.api.run("aggregate.assign_object", model, products=[site], relating_object=project)
# The site has a building, the building has a storey, and the storey has a space
ifcopenshell.api.run("aggregate.assign_object", model, product=building, relating_object=site)
ifcopenshell.api.run("aggregate.assign_object", model, product=storey, relating_object=building)
ifcopenshell.api.run("aggregate.assign_object", model, products=[building], relating_object=site)
ifcopenshell.api.run("aggregate.assign_object", model, products=[storey], relating_object=building)
# Create a wall
wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")