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,9 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.root
import ifcopenshell.api.system
import ifcopenshell.api.geometry
import ifcopenshell.util.system
import ifcopenshell.util.element
import ifcopenshell.util.placement
@@ -60,10 +62,10 @@ def copy_class(file: ifcopenshell.file, product: ifcopenshell.entity_instance) -
.. code:: python
# We have a wall
wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
# And now we have two
wall_copy = ifcopenshell.api.run("root.copy_class", model, product=wall)
wall_copy = ifcopenshell.api.root.copy_class(model, product=wall)
"""
usecase = Usecase()
usecase.file = file
@@ -104,7 +106,7 @@ class Usecase:
ports = [inverse.RelatingPort]
if not ports:
continue
new_ports = [ifcopenshell.api.run("root.copy_class", self.file, product=p) for p in ports]
new_ports = [ifcopenshell.api.root.copy_class(self.file, product=p) for p in ports]
inverse = ifcopenshell.util.element.copy(self.file, inverse)
if inverse.is_a("IfcRelNests"):
@@ -115,11 +117,10 @@ class Usecase:
inverse.RelatingPort = new_ports[0]
for port in new_ports:
ifcopenshell.api.run("system.unassign_port", self.file, element=from_element, port=port)
ifcopenshell.api.run("system.disconnect_port", self.file, port=port)
ifcopenshell.api.system.unassign_port(self.file, element=from_element, port=port)
ifcopenshell.api.system.disconnect_port(self.file, port=port)
matrix = ifcopenshell.util.placement.get_local_placement(port.ObjectPlacement)
ifcopenshell.api.run(
"geometry.edit_object_placement",
ifcopenshell.api.geometry.edit_object_placement(
self.file,
product=port,
matrix=matrix,
@@ -136,7 +137,7 @@ class Usecase:
opening = inverse.RelatedOpeningElement
# We don't copy filled openings, since there is no guarantee the filling is also copied
if not opening.is_a("IfcOpeningElement") or not opening.HasFillings:
new_opening = ifcopenshell.api.run("root.copy_class", self.file, product=opening)
new_opening = ifcopenshell.api.root.copy_class(self.file, product=opening)
new_opening.VoidsElements[0].RelatingBuildingElement = to_element
if new_opening.ObjectPlacement and new_opening.ObjectPlacement.is_a("IfcLocalPlacement"):
if to_element.ObjectPlacement:
@@ -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 Optional
@@ -58,16 +58,16 @@ def create_entity(
.. code:: python
# We have a project.
ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcProject")
ifcopenshell.api.root.create_entity(model, ifc_class="IfcProject")
# We have a building.
ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuilding")
ifcopenshell.api.root.create_entity(model, ifc_class="IfcBuilding")
# We have a wall.
ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
# We have a wall type.
ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWallType")
ifcopenshell.api.root.create_entity(model, ifc_class="IfcWallType")
"""
usecase = Usecase()
usecase.file = file
@@ -85,7 +85,7 @@ class Usecase:
self.settings["ifc_class"],
**{
"GlobalId": ifcopenshell.guid.new(),
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(self.file),
}
)
element.Name = self.settings["name"] or None
@@ -61,10 +61,10 @@ def reassign_class(
.. code:: python
# We have a wall.
wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
# Oh, did I say wall? I meant slab.
slab = ifcopenshell.api.run("root.reassign_class", model, product=wall, ifc_class="IfcSlab")
slab = ifcopenshell.api.root.reassign_class(model, product=wall, ifc_class="IfcSlab")
# Warning: this will crash since wall doesn't exist any more.
print(wall) # Kaboom.
@@ -16,7 +16,14 @@
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell.api
import ifcopenshell.api.type
import ifcopenshell.api.grid
import ifcopenshell.api.void
import ifcopenshell.api.root
import ifcopenshell.api.pset
import ifcopenshell.api.boundary
import ifcopenshell.api.material
import ifcopenshell.api.geometry
import ifcopenshell.util.element
@@ -50,10 +57,10 @@ def remove_product(file: ifcopenshell.file, product: ifcopenshell.entity_instanc
.. code:: python
# We have a wall.
wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
# No we don't.
ifcopenshell.api.run("root.remove_product", model, product=wall)
ifcopenshell.api.root.remove_product(model, product=wall)
"""
settings = {"product": product}
@@ -79,26 +86,19 @@ def remove_product(file: ifcopenshell.file, product: ifcopenshell.entity_instanc
for pset in psets:
if file.get_total_inverses(pset) != 1:
continue
ifcopenshell.api.run(
"pset.remove_pset",
file,
product=settings["product"],
pset=pset,
)
ifcopenshell.api.pset.remove_pset(file, product=settings["product"], pset=pset)
for representation in representations:
ifcopenshell.api.run(
"geometry.unassign_representation",
file,
**{"product": settings["product"], "representation": representation}
ifcopenshell.api.geometry.unassign_representation(
file, product=settings["product"], representation=representation
)
ifcopenshell.api.run("geometry.remove_representation", file, **{"representation": representation})
ifcopenshell.api.geometry.remove_representation(file, **{"representation": representation})
for opening in getattr(settings["product"], "HasOpenings", []) or []:
ifcopenshell.api.run("void.remove_opening", file, opening=opening.RelatedOpeningElement)
ifcopenshell.api.void.remove_opening(file, opening=opening.RelatedOpeningElement)
if settings["product"].is_a("IfcGrid"):
for axis in settings["product"].UAxes + settings["product"].VAxes + (settings["product"].WAxes or ()):
ifcopenshell.api.run("grid.remove_grid_axis", file, axis=axis)
ifcopenshell.api.grid.remove_grid_axis(file, axis=axis)
def element_exists(element_id):
try:
@@ -114,21 +114,18 @@ def remove_product(file: ifcopenshell.file, product: ifcopenshell.entity_instanc
except:
continue
if inverse.is_a("IfcRelDefinesByProperties"):
ifcopenshell.api.run(
"pset.remove_pset",
file,
product=settings["product"],
pset=inverse.RelatingPropertyDefinition,
ifcopenshell.api.pset.remove_pset(
file, product=settings["product"], pset=inverse.RelatingPropertyDefinition
)
elif inverse.is_a("IfcRelAssociatesMaterial"):
ifcopenshell.api.run("material.unassign_material", file, products=[settings["product"]])
ifcopenshell.api.material.unassign_material(file, products=[settings["product"]])
elif inverse.is_a("IfcRelDefinesByType"):
if inverse.RelatingType == settings["product"]:
ifcopenshell.api.run("type.unassign_type", file, related_objects=inverse.RelatedObjects)
ifcopenshell.api.type.unassign_type(file, related_objects=inverse.RelatedObjects)
else:
ifcopenshell.api.run("type.unassign_type", file, related_objects=[settings["product"]])
ifcopenshell.api.type.unassign_type(file, related_objects=[settings["product"]])
elif inverse.is_a("IfcRelSpaceBoundary"):
ifcopenshell.api.run("boundary.remove_boundary", file, boundary=inverse)
ifcopenshell.api.boundary.remove_boundary(file, boundary=inverse)
elif inverse.is_a("IfcRelFillsElement"):
history = inverse.OwnerHistory
file.remove(inverse)
@@ -149,7 +146,7 @@ def remove_product(file: ifcopenshell.file, product: ifcopenshell.entity_instanc
inverse_id = inverse.id()
for subelement in inverse.RelatedObjects:
if subelement.is_a("IfcDistributionPort"):
ifcopenshell.api.run("root.remove_product", file, product=subelement)
ifcopenshell.api.root.remove_product(file, product=subelement)
# IfcRelNests could have been already deleted after removing one of the products
if element_exists(inverse_id):
history = inverse.OwnerHistory
@@ -185,7 +182,7 @@ def remove_product(file: ifcopenshell.file, product: ifcopenshell.entity_instanc
ifcopenshell.util.element.remove_deep2(file, history)
elif inverse.is_a("IfcRelConnectsPortToElement"):
if inverse.RelatedElement == settings["product"]:
ifcopenshell.api.run("root.remove_product", file, product=inverse.RelatingPort)
ifcopenshell.api.root.remove_product(file, product=inverse.RelatingPort)
elif inverse.RelatingPort == settings["product"]:
history = inverse.OwnerHistory
file.remove(inverse)