Replace all ifcopenshell.api.run with ifcopenshell.api static functions.

This commit is contained in:
Dion Moult
2024-06-28 12:36:31 +10:00
parent b5d613989e
commit 07060fc769
432 changed files with 4633 additions and 4856 deletions
@@ -17,7 +17,8 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.root
import ifcopenshell.api.system
from typing import Optional
@@ -44,18 +45,18 @@ def add_port(file: ifcopenshell.file, element: Optional[ifcopenshell.entity_inst
.. code:: python
# Create a duct
duct = ifcopenshell.api.run("root.create_entity", model,
duct = ifcopenshell.api.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)
port1 = ifcopenshell.api.system.add_port(model, element=duct)
port2 = ifcopenshell.api.system.add_port(model, element=duct)
"""
settings = {
"element": element,
}
port = ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcDistributionPort")
port = ifcopenshell.api.root.create_entity(file, ifc_class="IfcDistributionPort")
if settings["element"]:
ifcopenshell.api.run("system.assign_port", file, element=settings["element"], port=port)
ifcopenshell.api.system.assign_port(file, element=settings["element"], port=port)
return port
@@ -17,7 +17,7 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.owner
import ifcopenshell.guid
@@ -43,7 +43,7 @@ def add_system(file: ifcopenshell.file, ifc_class: str = "IfcDistributionSystem"
.. code:: python
# A completely empty distribution system
system = ifcopenshell.api.run("system.add_system", model)
system = ifcopenshell.api.system.add_system(model)
"""
settings = {"ifc_class": ifc_class}
@@ -56,7 +56,7 @@ def add_system(file: ifcopenshell.file, ifc_class: str = "IfcDistributionSystem"
ifc_class,
**{
"GlobalId": ifcopenshell.guid.new(),
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", file),
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(file),
"Name": "Unnamed",
}
)
@@ -17,7 +17,7 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.owner
import ifcopenshell.guid
from typing import Union
@@ -47,9 +47,8 @@ def assign_flow_control(
flow_element = model.createIfcFlowSegment()
flow_control = model.createIfcController()
relation = ifcopenshell.api.run(
"system.assign_flow_control", model,
related_flow_control=flow_control, relating_flow_element=flow_element
relation = ifcopenshell.api.system.assign_flow_control(
model, related_flow_control=flow_control, relating_flow_element=flow_element
)
"""
settings = {
@@ -73,14 +72,14 @@ def assign_flow_control(
related_flow_controls = set(assignment.RelatedControlElements)
related_flow_controls.add(settings["related_flow_control"])
assignment.RelatedControlElements = list(related_flow_controls)
ifcopenshell.api.run("owner.update_owner_history", file, **{"element": assignment})
ifcopenshell.api.owner.update_owner_history(file, **{"element": assignment})
return assignment
assignment = file.create_entity(
"IfcRelFlowControlElements",
**{
"GlobalId": ifcopenshell.guid.new(),
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", file),
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(file),
"RelatedControlElements": [settings["related_flow_control"]],
"RelatingFlowElement": settings["relating_flow_element"],
},
@@ -17,7 +17,8 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.owner
import ifcopenshell.api.geometry
import ifcopenshell.guid
import ifcopenshell.util.placement
@@ -44,18 +45,18 @@ def assign_port(
.. code:: python
# Create a duct
duct = ifcopenshell.api.run("root.create_entity", model,
duct = ifcopenshell.api.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)
port1 = ifcopenshell.api.system.add_port(model, element=duct)
port2 = ifcopenshell.api.system.add_port(model, element=duct)
# Unassign one port for some weird reason.
ifcopenshell.api.run("system.unassign_port", model, element=duct, port=port1)
ifcopenshell.api.system.unassign_port(model, element=duct, port=port1)
# Reassign it back
ifcopenshell.api.run("system.assign_port", model, element=duct, port=port1)
ifcopenshell.api.system.assign_port(model, element=duct, port=port1)
"""
usecase = Usecase()
usecase.file = file
@@ -82,12 +83,12 @@ class Usecase:
related_objects = set(rel.RelatedObjects) or set()
related_objects.add(self.settings["port"])
rel.RelatedObjects = list(related_objects)
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": rel})
else:
rel = self.file.create_entity(
"IfcRelNests",
GlobalId=ifcopenshell.guid.new(),
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", self.file),
OwnerHistory=ifcopenshell.api.owner.create_owner_history(self.file),
RelatedObjects=[self.settings["port"]],
RelatingObject=self.settings["element"],
)
@@ -103,7 +104,7 @@ class Usecase:
rel = self.file.create_entity(
"IfcRelConnectsPortToElement",
GlobalId=ifcopenshell.guid.new(),
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", self.file),
OwnerHistory=ifcopenshell.api.owner.create_owner_history(self.file),
RelatingPort=self.settings["port"],
RelatedElement=self.settings["element"],
)
@@ -113,8 +114,7 @@ class Usecase:
def update_port_placement(self):
placement = getattr(self.settings["port"], "ObjectPlacement", None)
if placement and placement.is_a("IfcLocalPlacement"):
ifcopenshell.api.run(
"geometry.edit_object_placement",
ifcopenshell.api.geometry.edit_object_placement(
self.file,
product=self.settings["port"],
matrix=ifcopenshell.util.placement.get_local_placement(self.settings["port"].ObjectPlacement),
@@ -17,7 +17,7 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.group
import ifcopenshell.util.system
@@ -43,14 +43,14 @@ def assign_system(
.. code:: python
# A completely empty distribution system
system = ifcopenshell.api.run("system.add_system", model)
system = ifcopenshell.api.system.add_system(model)
# Create a duct
duct = ifcopenshell.api.run("root.create_entity", model,
duct = ifcopenshell.api.root.create_entity(model,
ifc_class="IfcDuctSegment", predefined_type="RIGIDSEGMENT")
# This duct is part of the system
ifcopenshell.api.run("system.assign_system", model, products=[duct], system=system)
ifcopenshell.api.system.assign_system(model, products=[duct], system=system)
"""
settings = {
"products": products,
@@ -63,5 +63,4 @@ def assign_system(
if not all(ifcopenshell.util.system.is_assignable(failed_product := product, system) for product in products):
raise TypeError(f"You cannot assign an {failed_product.is_a()} to an {system.is_a()}")
rel = ifcopenshell.api.run("group.assign_group", file, products=products, group=system)
return rel
return ifcopenshell.api.group.assign_group(file, products=products, group=system)
@@ -17,7 +17,7 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.owner
import ifcopenshell.guid
import ifcopenshell.util.element
from typing import Optional
@@ -75,28 +75,28 @@ def connect_port(
.. code:: python
# A completely empty distribution system
system = ifcopenshell.api.run("system.add_system", model)
system = ifcopenshell.api.system.add_system(model)
# Create a duct and a 90 degree bend fitting
duct = ifcopenshell.api.run("root.create_entity", model,
duct = ifcopenshell.api.root.create_entity(model,
ifc_class="IfcDuctSegment", predefined_type="RIGIDSEGMENT")
fitting = ifcopenshell.api.run("root.create_entity", model,
fitting = ifcopenshell.api.root.create_entity(model,
ifc_class="IfcDuctFitting", predefined_type="BEND")
# The duct and fitting is part of the system
ifcopenshell.api.run("system.assign_system", model, products=[duct], system=system)
ifcopenshell.api.run("system.assign_system", model, products=[fitting], system=system)
ifcopenshell.api.system.assign_system(model, products=[duct], system=system)
ifcopenshell.api.system.assign_system(model, products=[fitting], system=system)
# Create 2 ports, one for either end of both the duct and fitting.
duct_port1 = ifcopenshell.api.run("system.add_port", model, element=duct)
duct_port2 = ifcopenshell.api.run("system.add_port", model, element=duct)
fitting_port1 = ifcopenshell.api.run("system.add_port", model, element=fitting)
fitting_port2 = ifcopenshell.api.run("system.add_port", model, element=fitting)
duct_port1 = ifcopenshell.api.system.add_port(model, element=duct)
duct_port2 = ifcopenshell.api.system.add_port(model, element=duct)
fitting_port1 = ifcopenshell.api.system.add_port(model, element=fitting)
fitting_port2 = ifcopenshell.api.system.add_port(model, element=fitting)
# Connect the duct and fitting together. At this point, we have not
# yet determined the direction of the flow, so we leave direction as
# NOTDEFINED.
ifcopenshell.api.run("system.connect_port", model, port1=duct_port2, port2=fitting_port1)
ifcopenshell.api.system.connect_port(model, port1=duct_port2, port2=fitting_port1)
"""
usecase = Usecase()
usecase.file = file
@@ -180,7 +180,7 @@ class Usecase:
self.file.create_entity(
"IfcRelConnectsPorts",
GlobalId=ifcopenshell.guid.new(),
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", self.file),
OwnerHistory=ifcopenshell.api.owner.create_owner_history(self.file),
RelatingPort=self.settings["port1"],
RelatedPort=self.settings["port2"],
)
@@ -192,7 +192,7 @@ class Usecase:
self.file.create_entity(
"IfcRelConnectsPorts",
GlobalId=ifcopenshell.guid.new(),
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", self.file),
OwnerHistory=ifcopenshell.api.owner.create_owner_history(self.file),
RelatingPort=self.settings["port2"],
RelatedPort=self.settings["port1"],
)
@@ -37,32 +37,32 @@ def disconnect_port(file: ifcopenshell.file, port: ifcopenshell.entity_instance)
.. code:: python
# A completely empty distribution system
system = ifcopenshell.api.run("system.add_system", model)
system = ifcopenshell.api.system.add_system(model)
# Create a duct and a 90 degree bend fitting
duct = ifcopenshell.api.run("root.create_entity", model,
duct = ifcopenshell.api.root.create_entity(model,
ifc_class="IfcDuctSegment", predefined_type="RIGIDSEGMENT")
fitting = ifcopenshell.api.run("root.create_entity", model,
fitting = ifcopenshell.api.root.create_entity(model,
ifc_class="IfcDuctFitting", predefined_type="BEND")
# The duct and fitting is part of the system
ifcopenshell.api.run("system.assign_system", model, products=[duct], system=system)
ifcopenshell.api.run("system.assign_system", model, products=[fitting], system=system)
ifcopenshell.api.system.assign_system(model, products=[duct], system=system)
ifcopenshell.api.system.assign_system(model, products=[fitting], system=system)
# Create 2 ports, one for either end of both the duct and fitting.
duct_port1 = ifcopenshell.api.run("system.add_port", model, element=duct)
duct_port2 = ifcopenshell.api.run("system.add_port", model, element=duct)
fitting_port1 = ifcopenshell.api.run("system.add_port", model, element=fitting)
fitting_port2 = ifcopenshell.api.run("system.add_port", model, element=fitting)
duct_port1 = ifcopenshell.api.system.add_port(model, element=duct)
duct_port2 = ifcopenshell.api.system.add_port(model, element=duct)
fitting_port1 = ifcopenshell.api.system.add_port(model, element=fitting)
fitting_port2 = ifcopenshell.api.system.add_port(model, element=fitting)
# Connect the duct and fitting together. At this point, we have not
# yet determined the direction of the flow, so we leave direction as
# NOTDEFINED.
ifcopenshell.api.run("system.connect_port", model, port1=duct_port2, port2=fitting_port1)
ifcopenshell.api.system.connect_port(model, port1=duct_port2, port2=fitting_port1)
# Disconnect the port. note we could've equally disconnected
# fitting_port1 instead of duct_port2
ifcopenshell.api.run("system.disconnect_port", model, port=duct_port2)
ifcopenshell.api.system.disconnect_port(model, port=duct_port2)
"""
settings = {
"port": port,
@@ -37,10 +37,10 @@ def edit_system(file: ifcopenshell.file, system: ifcopenshell.entity_instance, a
.. code:: python
# A completely empty distribution system
system = ifcopenshell.api.run("system.add_system", model)
system = ifcopenshell.api.system.add_system(model)
# Change the name of the system to "HW" for Hot Water
ifcopenshell.api.run("system.edit_system", model, system=system, attributes={"Name": "HW"})
ifcopenshell.api.system.edit_system(model, system=system, attributes={"Name": "HW"})
"""
settings = {"system": system, "attributes": attributes or {}}
@@ -17,7 +17,7 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.pset
import ifcopenshell.util.element
@@ -36,10 +36,10 @@ def remove_system(file: ifcopenshell.file, system: ifcopenshell.entity_instance)
.. code:: python
# A completely empty distribution system
system = ifcopenshell.api.run("system.add_system", model)
system = ifcopenshell.api.system.add_system(model)
# Delete it.
ifcopenshell.api.run("system.remove_system", model, system=system)
ifcopenshell.api.system.remove_system(model, system=system)
"""
settings = {"system": system}
@@ -49,8 +49,7 @@ def remove_system(file: ifcopenshell.file, system: ifcopenshell.entity_instance)
except:
continue
if inverse.is_a("IfcRelDefinesByProperties"):
ifcopenshell.api.run(
"pset.remove_pset",
ifcopenshell.api.pset.remove_pset(
file,
product=settings["system"],
pset=inverse.RelatingPropertyDefinition,
@@ -17,7 +17,7 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.owner
import ifcopenshell.util.element
@@ -43,13 +43,12 @@ def unassign_flow_control(
# assign control to the flow element
flow_element = file.createIfcFlowSegment()
flow_control = file.createIfcController()
relation = ifcopenshell.api.run(
"system.assign_flow_control", file,
relating_control=flow_control, related_object=flow_element
relation = ifcopenshell.api.system.assign_flow_control(
file, relating_control=flow_control, related_object=flow_element
)
# und unassign it
ifcopenshell.api.run("system.unassign_flow_control", file,
ifcopenshell.api.system.unassign_flow_control(file,
relating_control=flow_control, related_object=flow_element
)
"""
@@ -73,4 +72,4 @@ def unassign_flow_control(
related_flow_controls = list(assignment.RelatedControlElements)
related_flow_controls.remove(settings["related_flow_control"])
assignment.RelatedControlElements = related_flow_controls
ifcopenshell.api.run("owner.update_owner_history", file, **{"element": assignment})
ifcopenshell.api.owner.update_owner_history(file, **{"element": assignment})
@@ -17,7 +17,7 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.owner
import ifcopenshell.util.element
@@ -42,15 +42,15 @@ def unassign_port(
.. code:: python
# Create a duct
duct = ifcopenshell.api.run("root.create_entity", model,
duct = ifcopenshell.api.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)
port1 = ifcopenshell.api.system.add_port(model, element=duct)
port2 = ifcopenshell.api.system.add_port(model, element=duct)
# Unassign one port for some weird reason.
ifcopenshell.api.run("system.unassign_port", model, element=duct, port=port1)
ifcopenshell.api.system.unassign_port(model, element=duct, port=port1)
"""
usecase = Usecase()
usecase.file = file
@@ -77,7 +77,7 @@ class Usecase:
related_objects = set(rel.RelatedObjects) or set()
related_objects.remove(self.settings["port"])
rel.RelatedObjects = list(related_objects)
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(self.file, **{"element": rel})
def execute_ifc2x3(self):
for rel in self.settings["element"].HasPorts or []:
@@ -17,7 +17,7 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.group
import ifcopenshell.util.element
@@ -40,21 +40,21 @@ def unassign_system(
.. code:: python
# A completely empty distribution system
system = ifcopenshell.api.run("system.add_system", model)
system = ifcopenshell.api.system.add_system(model)
# Create a duct
duct = ifcopenshell.api.run("root.create_entity", model,
duct = ifcopenshell.api.root.create_entity(model,
ifc_class="IfcDuctSegment", predefined_type="RIGIDSEGMENT")
# This duct is part of the system
ifcopenshell.api.run("system.assign_system", model, products=[duct], system=system)
ifcopenshell.api.system.assign_system(model, products=[duct], system=system)
# Not anymore!
ifcopenshell.api.run("system.unassign_system", model, products=[duct], system=system)
ifcopenshell.api.system.unassign_system(model, products=[duct], system=system)
"""
settings = {
"products": products,
"system": system,
}
ifcopenshell.api.run("group.unassign_group", file, products=settings["products"], group=settings["system"])
ifcopenshell.api.group.unassign_group(file, products=settings["products"], group=settings["system"])