mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-14 03:14:23 +00:00
Generate functions for all API usecases for better static code features. See #2693.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user