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
@@ -58,6 +58,6 @@ def add_library(file: ifcopenshell.file, name: str) -> ifcopenshell.entity_insta
.. code:: python
ifcopenshell.api.run("library.add_library", model, name="Brickschema")
ifcopenshell.api.library.add_library(model, name="Brickschema")
"""
return file.create_entity("IfcLibraryInformation", Name=name)
@@ -43,11 +43,11 @@ def add_reference(file: ifcopenshell.file, library: ifcopenshell.entity_instance
.. code:: python
library = ifcopenshell.api.run("library.add_library", model, name="Brickschema")
library = ifcopenshell.api.library.add_library(model, name="Brickschema")
# Let's create a reference to a single AHU in our Brickschema dataset
reference = ifcopenshell.api.run("library.add_reference", model, library=library)
ifcopenshell.api.run("library.edit_reference", model,
reference = ifcopenshell.api.library.add_reference(model, library=library)
ifcopenshell.api.library.edit_reference(model,
reference=reference, attributes={"Identification": "http://example.org/digitaltwin#AHU01"})
"""
settings = {
@@ -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
@@ -46,19 +46,19 @@ def assign_reference(
.. code:: python
library = ifcopenshell.api.run("library.add_library", model, name="Brickschema")
library = ifcopenshell.api.library.add_library(model, name="Brickschema")
# Let's create a reference to a single AHU in our Brickschema dataset
reference = ifcopenshell.api.run("library.add_reference", model, library=library)
ifcopenshell.api.run("library.edit_reference", model,
reference = ifcopenshell.api.library.add_reference(model, library=library)
ifcopenshell.api.library.edit_reference(model,
reference=reference, attributes={"Identification": "http://example.org/digitaltwin#AHU01"})
# Let's assume we have an AHU in our model.
ahu = ifcopenshell.api.run("root.create_entity", model,
ahu = ifcopenshell.api.root.create_entity(model,
ifc_class="IfcUnitaryEquipment", predefined_type="AIRHANDLER")
# And now assign the IFC model's AHU with its Brickschema counterpart
ifcopenshell.api.run("library.assign_reference", model, reference=reference, products=[ahu])
ifcopenshell.api.library.assign_reference(model, reference=reference, products=[ahu])
"""
settings = {
"products": products,
@@ -86,12 +86,12 @@ def assign_reference(
return file.create_entity(
"IfcRelAssociatesLibrary",
GlobalId=ifcopenshell.guid.new(),
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", file),
OwnerHistory=ifcopenshell.api.owner.create_owner_history(file),
RelatedObjects=list(products),
RelatingLibrary=settings["reference"],
)
related_objects = set(rel.RelatedObjects) | products
rel.RelatedObjects = list(related_objects)
ifcopenshell.api.run("owner.update_owner_history", file, element=rel)
ifcopenshell.api.owner.update_owner_history(file, element=rel)
return rel
@@ -38,8 +38,8 @@ def edit_library(file: ifcopenshell.file, library: ifcopenshell.entity_instance,
.. code:: python
library = ifcopenshell.api.run("library.add_library", model, name="Brickschema")
ifcopenshell.api.run("library.edit_library", model, library=library,
library = ifcopenshell.api.library.add_library(model, name="Brickschema")
ifcopenshell.api.library.edit_library(model, library=library,
attributes={"Description": "A Brickschema TTL including only mechanical distribution systems."})
"""
@@ -38,10 +38,10 @@ def edit_reference(
.. code:: python
library = ifcopenshell.api.run("library.add_library", model, name="Brickschema")
library = ifcopenshell.api.library.add_library(model, name="Brickschema")
# Let's create a reference to a single AHU in our Brickschema dataset
reference = ifcopenshell.api.run("library.add_reference", model, library=library)
ifcopenshell.api.run("library.edit_reference", model,
reference = ifcopenshell.api.library.add_reference(model, library=library)
ifcopenshell.api.library.edit_reference(model,
reference=reference, attributes={"Identification": "http://example.org/digitaltwin#AHU01"})
"""
settings = {"reference": reference, "attributes": attributes}
@@ -35,8 +35,8 @@ def remove_library(file: ifcopenshell.file, library: ifcopenshell.entity_instanc
.. code:: python
library = ifcopenshell.api.run("library.add_library", model, name="Brickschema")
ifcopenshell.api.run("library.remove_library", model, library=library)
library = ifcopenshell.api.library.add_library(model, name="Brickschema")
ifcopenshell.api.library.remove_library(model, library=library)
"""
if file.schema != "IFC2X3":
@@ -35,10 +35,10 @@ def remove_reference(file: ifcopenshell.file, reference: ifcopenshell.entity_ins
.. code:: python
library = ifcopenshell.api.run("library.add_library", model, name="Brickschema")
reference = ifcopenshell.api.run("library.add_reference", model, library=library)
library = ifcopenshell.api.library.add_library(model, name="Brickschema")
reference = ifcopenshell.api.library.add_reference(model, library=library)
# Let's change our mind and remove it.
ifcopenshell.api.run("library.remove_reference", model, reference=reference)
ifcopenshell.api.library.remove_reference(model, reference=reference)
"""
if file.schema != "IFC2X3":
rels = reference.LibraryRefForObjects
@@ -18,7 +18,7 @@
import ifcopenshell
import ifcopenshell.util.element
import ifcopenshell.api
import ifcopenshell.api.owner
def unassign_reference(
@@ -41,22 +41,22 @@ def unassign_reference(
.. code:: python
library = ifcopenshell.api.run("library.add_library", model, name="Brickschema")
library = ifcopenshell.api.library.add_library(model, name="Brickschema")
# Let's create a reference to a single AHU in our Brickschema dataset
reference = ifcopenshell.api.run("library.add_reference", model, library=library)
ifcopenshell.api.run("library.edit_reference", model,
reference = ifcopenshell.api.library.add_reference(model, library=library)
ifcopenshell.api.library.edit_reference(model,
reference=reference, attributes={"Identification": "http://example.org/digitaltwin#AHU01"})
# Let's assume we have an AHU in our model.
ahu = ifcopenshell.api.run("root.create_entity", model,
ahu = ifcopenshell.api.root.create_entity(model,
ifc_class="IfcUnitaryEquipment", predefined_type="AIRHANDLER")
# And now assign the IFC model's AHU with its Brickschema counterpart
ifcopenshell.api.run("library.assign_reference", model, reference=reference, products=[ahu])
ifcopenshell.api.library.assign_reference(model, reference=reference, products=[ahu])
# Let's change our mind and unassign it.
ifcopenshell.api.run("library.unassign_reference", model, reference=reference, products=[ahu])
ifcopenshell.api.library.unassign_reference(model, reference=reference, products=[ahu])
"""
settings = {"reference": reference, "products": products}
@@ -78,7 +78,7 @@ def unassign_reference(
related_objects = set(rel.RelatedObjects) - products
if related_objects:
rel.RelatedObjects = list(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)