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,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 Union
@@ -92,11 +92,11 @@ def assign_object(
.. code:: python
# Faucets are designed to attach onto a sink through a predrilled hole.
sink = ifcopenshell.api.run("root.create_entity", model,
sink = ifcopenshell.api.root.create_entity(model,
ifc_class="IfcSanitaryTerminal", predefined_type="SINK")
faucet = ifcopenshell.api.run("root.create_entity", model,
faucet = ifcopenshell.api.root.create_entity(model,
ifc_class="IfcValve", predefined_type="FAUCET")
ifcopenshell.api.run("nest.assign_object", model, related_objects=[faucet], relating_object=sink)
ifcopenshell.api.nest.assign_object(model, related_objects=[faucet], relating_object=sink)
"""
settings = {"related_objects": related_objects, "relating_object": relating_object}
@@ -146,7 +146,7 @@ def assign_object(
cur_related_objects = [o for o in nests.RelatedObjects if o not in related_objects_set]
if cur_related_objects:
nests.RelatedObjects = list(cur_related_objects)
ifcopenshell.api.run("owner.update_owner_history", file, **{"element": nests})
ifcopenshell.api.owner.update_owner_history(file, **{"element": nests})
else:
history = nests.OwnerHistory
file.remove(nests)
@@ -160,13 +160,13 @@ def assign_object(
is_nested_by.RelatedObjects = cur_related_objects + [
o for o in related_objects if o not in cur_related_objects_set
]
ifcopenshell.api.run("owner.update_owner_history", file, **{"element": is_nested_by})
ifcopenshell.api.owner.update_owner_history(file, **{"element": is_nested_by})
else:
is_nested_by = file.create_entity(
"IfcRelNests",
**{
"GlobalId": ifcopenshell.guid.new(),
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", file),
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(file),
"RelatedObjects": related_objects,
"RelatingObject": relating_object,
}
@@ -17,7 +17,8 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.nest
import ifcopenshell.api.owner
import ifcopenshell.util.element
@@ -32,15 +33,10 @@ def change_nest(
related_objects.remove(item)
if related_objects:
nests.RelatedObjects = related_objects
ifcopenshell.api.run("owner.update_owner_history", file, **{"element": nests})
ifcopenshell.api.owner.update_owner_history(file, **{"element": nests})
else:
history = nests.OwnerHistory
file.remove(nests)
if history:
ifcopenshell.util.element.remove_deep2(file, history)
ifcopenshell.api.run(
"nest.assign_object",
file,
related_objects=[item],
relating_object=new_parent,
)
ifcopenshell.api.nest.assign_object(file, related_objects=[item], relating_object=new_parent)
@@ -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
@@ -39,15 +39,15 @@ def unassign_object(file: ifcopenshell.file, related_objects: list[ifcopenshell.
.. code:: python
task = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcTasks")
subtask1 = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcTask")
subtask2 = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcTask")
ifcopenshell.api.run("nest.assign_object", model, related_objects=[subtask1], relating_object=task)
ifcopenshell.api.run("nest.assign_object", model, related_objects=[subtask2], relating_object=task)
task = ifcopenshell.api.root.create_entity(model, ifc_class="IfcTasks")
subtask1 = ifcopenshell.api.root.create_entity(model, ifc_class="IfcTask")
subtask2 = ifcopenshell.api.root.create_entity(model, ifc_class="IfcTask")
ifcopenshell.api.nest.assign_object(model, related_objects=[subtask1], relating_object=task)
ifcopenshell.api.nest.assign_object(model, related_objects=[subtask2], relating_object=task)
# nothing is returned
rel = ifcopenshell.api.run("nest.unassign_object", model, related_objects=[subtask1])
rel = ifcopenshell.api.nest.unassign_object(model, related_objects=[subtask1])
# nothing is returned, relationship is removed
ifcopenshell.api.run("nest.unassign_object", model, related_objects=[subtask2])
ifcopenshell.api.nest.unassign_object(model, related_objects=[subtask2])
"""
# NOTE: maintain .RelatedObjects order as it has meaning in IFC
@@ -66,7 +66,7 @@ def unassign_object(file: ifcopenshell.file, related_objects: list[ifcopenshell.
cur_related_objects = [o for o in rel.RelatedObjects if o not in related_objects_set]
if cur_related_objects:
rel.RelatedObjects = cur_related_objects
ifcopenshell.api.run("owner.update_owner_history", file, **{"element": rel})
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
else:
history = rel.OwnerHistory
file.remove(rel)