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,46 +21,49 @@ import ifcopenshell.api
import ifcopenshell.util.placement
def assign_port(file, element=None, port=None) -> None:
"""Assigns a port to an element
If you have an orphaned port, you may assign it to a distribution
element using this function. Ports should typically not be orphaned, but
it may be useful when patching up models.
:param element: The IfcDistributionElement to assign the port to.
:type element: ifcopenshell.entity_instance
:param port: The IfcDistributionPort you want to assign.
:type port: ifcopenshell.entity_instance
:return: The IfcRelNests relationship, or the
IfcRelConnectsPortToElement for IFC2X3.
:rtype: ifcopenshell.entity_instance
Example:
.. code:: python
# Create a duct
duct = ifcopenshell.api.run("root.create_entity", model,
ifc_class="IfcDuctSegment", predefined_type="RIGIDSEGMENT")
# Create 2 ports, one for either end.
port1 = ifcopenshell.api.run("system.add_port", model, element=duct)
port2 = ifcopenshell.api.run("system.add_port", model, element=duct)
# Unassign one port for some weird reason.
ifcopenshell.api.run("system.unassign_port", model, element=duct, port=port1)
# Reassign it back
ifcopenshell.api.run("system.assign_port", model, element=duct, port=port1)
"""
usecase = Usecase()
usecase.file = file
usecase.settings = {
"element": element,
"port": port,
}
return usecase.execute()
class Usecase:
def __init__(self, file, element=None, port=None):
"""Assigns a port to an element
If you have an orphaned port, you may assign it to a distribution
element using this function. Ports should typically not be orphaned, but
it may be useful when patching up models.
:param element: The IfcDistributionElement to assign the port to.
:type element: ifcopenshell.entity_instance
:param port: The IfcDistributionPort you want to assign.
:type port: ifcopenshell.entity_instance
:return: The IfcRelNests relationship, or the
IfcRelConnectsPortToElement for IFC2X3.
:rtype: ifcopenshell.entity_instance
Example:
.. code:: python
# Create a duct
duct = ifcopenshell.api.run("root.create_entity", model,
ifc_class="IfcDuctSegment", predefined_type="RIGIDSEGMENT")
# Create 2 ports, one for either end.
port1 = ifcopenshell.api.run("system.add_port", model, element=duct)
port2 = ifcopenshell.api.run("system.add_port", model, element=duct)
# Unassign one port for some weird reason.
ifcopenshell.api.run("system.unassign_port", model, element=duct, port=port1)
# Reassign it back
ifcopenshell.api.run("system.assign_port", model, element=duct, port=port1)
"""
self.file = file
self.settings = {
"element": element,
"port": port,
}
def execute(self):
if self.file.schema == "IFC2X3":
return self.execute_ifc2x3()