mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 10:33:20 +00:00
Generate functions for all API usecases for better static code features. See #2693.
This commit is contained in:
@@ -21,56 +21,53 @@ import ifcopenshell.api
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file: ifcopenshell.file, products: list[ifcopenshell.entity_instance]):
|
||||
"""Unassigns a container from products.
|
||||
def unassign_container(file: ifcopenshell.file, products: list[ifcopenshell.entity_instance]) -> None:
|
||||
"""Unassigns a container from products.
|
||||
|
||||
:param product: A list of IfcProducts to remove the containment from.
|
||||
:type product: list[ifcopenshell.entity_instance]
|
||||
:return: None
|
||||
:rtype: None
|
||||
:param product: A list of IfcProducts to remove the containment from.
|
||||
:type product: list[ifcopenshell.entity_instance]
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
.. code:: python
|
||||
|
||||
project = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcProject")
|
||||
site = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcSite")
|
||||
building = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuilding")
|
||||
storey = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuildingStorey")
|
||||
project = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcProject")
|
||||
site = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcSite")
|
||||
building = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuilding")
|
||||
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, products=[site], relating_object=project)
|
||||
# The project contains a site (note that project aggregation is a special case in IFC)
|
||||
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, products=[building], relating_object=site)
|
||||
ifcopenshell.api.run("aggregate.assign_object", model, products=[storey], relating_object=building)
|
||||
# The site has a building, the building has a storey, and the storey has a space
|
||||
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")
|
||||
# Create a wall
|
||||
wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
|
||||
|
||||
# The wall is in the storey
|
||||
ifcopenshell.api.run("spatial.assign_container", model, products=[wall], relating_structure=storey)
|
||||
# The wall is in the storey
|
||||
ifcopenshell.api.run("spatial.assign_container", model, products=[wall], relating_structure=storey)
|
||||
|
||||
# Not anymore!
|
||||
ifcopenshell.api.run("spatial.unassign_container", model, products=[wall])
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"products": products,
|
||||
}
|
||||
# Not anymore!
|
||||
ifcopenshell.api.run("spatial.unassign_container", model, products=[wall])
|
||||
"""
|
||||
settings = {
|
||||
"products": products,
|
||||
}
|
||||
|
||||
def execute(self) -> None:
|
||||
products = set(self.settings["products"])
|
||||
rels = set(rel for product in products if (rel := next(iter(product.ContainedInStructure), None)))
|
||||
products = set(settings["products"])
|
||||
rels = set(rel for product in products if (rel := next(iter(product.ContainedInStructure), None)))
|
||||
|
||||
for rel in rels:
|
||||
related_elements = set(rel.RelatedElements) - products
|
||||
if related_elements:
|
||||
rel.RelatedElements = list(related_elements)
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, element=rel)
|
||||
else:
|
||||
history = rel.OwnerHistory
|
||||
self.file.remove(rel)
|
||||
if history:
|
||||
ifcopenshell.util.element.remove_deep2(self.file, history)
|
||||
for rel in rels:
|
||||
related_elements = set(rel.RelatedElements) - products
|
||||
if related_elements:
|
||||
rel.RelatedElements = list(related_elements)
|
||||
ifcopenshell.api.run("owner.update_owner_history", file, element=rel)
|
||||
else:
|
||||
history = rel.OwnerHistory
|
||||
file.remove(rel)
|
||||
if history:
|
||||
ifcopenshell.util.element.remove_deep2(file, history)
|
||||
|
||||
Reference in New Issue
Block a user