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,55 +21,52 @@ import ifcopenshell.api
import ifcopenshell.util.element
class Usecase:
def __init__(self, file, system=None):
"""Removes a distribution system
def remove_system(file, system=None) -> None:
"""Removes a distribution system
All the distribution elements within the system are retained.
All the distribution elements within the system are retained.
:param system: The IfcSystem to remove.
:type system: ifcopenshell.entity_instance
:return: None
:rtype: None
:param system: The IfcSystem to remove.
:type system: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
Example:
.. code:: python
.. code:: python
# A completely empty distribution system
system = ifcopenshell.api.run("system.add_system", model)
# A completely empty distribution system
system = ifcopenshell.api.run("system.add_system", model)
# Delete it.
ifcopenshell.api.run("system.remove_system", model, system=system)
"""
self.file = file
self.settings = {"system": system}
# Delete it.
ifcopenshell.api.run("system.remove_system", model, system=system)
"""
settings = {"system": system}
def execute(self):
for inverse_id in [i.id() for i in self.file.get_inverse(self.settings["system"])]:
try:
inverse = self.file.by_id(inverse_id)
except:
continue
if inverse.is_a("IfcRelDefinesByProperties"):
ifcopenshell.api.run(
"pset.remove_pset",
self.file,
product=self.settings["system"],
pset=inverse.RelatingPropertyDefinition,
)
elif inverse.is_a("IfcRelAssignsToGroup"):
if inverse.RelatingGroup == self.settings["system"]:
history = inverse.OwnerHistory
self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
elif len(inverse.RelatedObjects) == 1:
history = inverse.OwnerHistory
self.file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
history = self.settings["system"].OwnerHistory
self.file.remove(self.settings["system"])
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
for inverse_id in [i.id() for i in file.get_inverse(settings["system"])]:
try:
inverse = file.by_id(inverse_id)
except:
continue
if inverse.is_a("IfcRelDefinesByProperties"):
ifcopenshell.api.run(
"pset.remove_pset",
file,
product=settings["system"],
pset=inverse.RelatingPropertyDefinition,
)
elif inverse.is_a("IfcRelAssignsToGroup"):
if inverse.RelatingGroup == settings["system"]:
history = inverse.OwnerHistory
file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(file, history)
elif len(inverse.RelatedObjects) == 1:
history = inverse.OwnerHistory
file.remove(inverse)
if history:
ifcopenshell.util.element.remove_deep2(file, history)
history = settings["system"].OwnerHistory
file.remove(settings["system"])
if history:
ifcopenshell.util.element.remove_deep2(file, history)