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,41 +21,44 @@ import ifcopenshell.api
import ifcopenshell.util.element
def unassign_material(file: ifcopenshell.file, products: list[ifcopenshell.entity_instance]) -> None:
"""Removes any material relationship with the list of products
A product can only have one material assigned to it, which is why it is
not necessary to specify the material to unassign. The material is not
removed, only the relationship is removed.
If the product does not have a material, nothing happens.
:param products: The list IfcProducts that may or may not have a material
:type product: list[ifcopenshell.entity_instance]
:return: None
:rtype: None
Example:
.. code:: python
concrete = ifcopenshell.api.run("material.add_material", model, name="CON01", category="concrete")
# Let's imagine a concrete bench made out of concrete.
bench_type = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcFurnitureType")
ifcopenshell.api.run("material.assign_material", model,
products=[bench_type], type="IfcMaterial", material=concrete)
# Let's change our mind and remove the concrete assignment. The
# concrete material still exists, but the bench is no longer made
# out of concrete now.
ifcopenshell.api.run("material.unassign_material", model, products=[bench_type])
"""
usecase = Usecase()
usecase.file = file
usecase.settings = {"products": products}
return usecase.execute()
class Usecase:
def __init__(self, file: ifcopenshell.file, products: list[ifcopenshell.entity_instance]):
"""Removes any material relationship with the list of products
A product can only have one material assigned to it, which is why it is
not necessary to specify the material to unassign. The material is not
removed, only the relationship is removed.
If the product does not have a material, nothing happens.
:param products: The list IfcProducts that may or may not have a material
:type product: list[ifcopenshell.entity_instance]
:return: None
:rtype: None
Example:
.. code:: python
concrete = ifcopenshell.api.run("material.add_material", model, name="CON01", category="concrete")
# Let's imagine a concrete bench made out of concrete.
bench_type = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcFurnitureType")
ifcopenshell.api.run("material.assign_material", model,
products=[bench_type], type="IfcMaterial", material=concrete)
# Let's change our mind and remove the concrete assignment. The
# concrete material still exists, but the bench is no longer made
# out of concrete now.
ifcopenshell.api.run("material.unassign_material", model, products=[bench_type])
"""
self.file = file
self.settings = {"products": products}
def execute(self) -> None:
def execute(self):
self.products = set(self.settings["products"])
if not self.products:
return