Generate functions for all API usecases for better static code features. See #2693.

This commit is contained in:
Dion Moult
2024-05-06 14:35:39 +10:00
parent 10f894e2ea
commit d11ec67129
330 changed files with 13283 additions and 13751 deletions
@@ -21,48 +21,47 @@ import ifcopenshell.api
import ifcopenshell.util.element
class Usecase:
def __init__(self, file: ifcopenshell.file, products: list[ifcopenshell.entity_instance], group: ifcopenshell.entity_instance):
"""Unassigns products from a group
def unassign_group(
file: ifcopenshell.file, products: list[ifcopenshell.entity_instance], group: ifcopenshell.entity_instance
) -> None:
"""Unassigns products from a group
If the product isn't assigned to the group, nothing will happen.
If the product isn't assigned to the group, nothing will happen.
:param products: A list of IfcProduct elements to unassign from the group
:type products: list[ifcopenshell.entity_instance]
:param group: The IfcGroup to unassign from
:type group: ifcopenshell.entity_instance
:return: None
:rtype: None
:param products: A list of IfcProduct elements to unassign from the group
:type products: list[ifcopenshell.entity_instance]
:param group: The IfcGroup to unassign from
:type group: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
Example:
.. code:: python
.. code:: python
group = ifcopenshell.api.run("group.add_group", model, Name="Furniture")
furniture = model.by_type("IfcFurniture")
ifcopenshell.api.run("group.assign_group", model, products=furniture, group=group)
group = ifcopenshell.api.run("group.add_group", model, Name="Furniture")
furniture = model.by_type("IfcFurniture")
ifcopenshell.api.run("group.assign_group", model, products=furniture, group=group)
bad_furniture = furniture[0]
ifcopenshell.api.run("group.unassign_group", model, products=[bad_furniture], group=group)
"""
self.file = file
self.settings = {
"products": products,
"group": group,
}
bad_furniture = furniture[0]
ifcopenshell.api.run("group.unassign_group", model, products=[bad_furniture], group=group)
"""
settings = {
"products": products,
"group": group,
}
def execute(self) -> None:
if not self.settings["group"].IsGroupedBy:
return
rel = self.settings["group"].IsGroupedBy[0]
related_objects = set(rel.RelatedObjects) or set()
products = set(self.settings["products"])
related_objects -= products
if related_objects:
rel.RelatedObjects = list(related_objects)
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)
if not settings["group"].IsGroupedBy:
return
rel = settings["group"].IsGroupedBy[0]
related_objects = set(rel.RelatedObjects) or set()
products = set(settings["products"])
related_objects -= products
if related_objects:
rel.RelatedObjects = list(related_objects)
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)