mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Replace all ifcopenshell.api.run with ifcopenshell.api static functions.
This commit is contained in:
@@ -16,7 +16,9 @@
|
||||
# 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.root
|
||||
import ifcopenshell.api.nest
|
||||
import ifcopenshell.api.project
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@@ -69,10 +71,10 @@ def add_resource(
|
||||
.. code:: python
|
||||
|
||||
# Add our own crew
|
||||
crew = ifcopenshell.api.run("resource.add_resource", model, ifc_class="IfcCrewResource")
|
||||
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
||||
|
||||
# Add some labour to our crew.
|
||||
ifcopenshell.api.run("resource.add_resource", model, parent_resource=crew, ifc_class="IfcLaborResource")
|
||||
ifcopenshell.api.resource.add_resource(model, parent_resource=crew, ifc_class="IfcLaborResource")
|
||||
"""
|
||||
settings = {
|
||||
"parent_resource": parent_resource,
|
||||
@@ -81,8 +83,7 @@ def add_resource(
|
||||
"predefined_type": predefined_type,
|
||||
}
|
||||
|
||||
resource = ifcopenshell.api.run(
|
||||
"root.create_entity",
|
||||
resource = ifcopenshell.api.root.create_entity(
|
||||
file,
|
||||
ifc_class=settings["ifc_class"],
|
||||
predefined_type=settings["predefined_type"],
|
||||
@@ -91,18 +92,10 @@ def add_resource(
|
||||
# TODO: this is an ambiguity by buildingSMART: Can we nest an IfcCrewResource under an IfcCrewResource ?
|
||||
# https://forums.buildingsmart.org/t/what-are-allowed-to-be-root-level-construction-resources/3550
|
||||
if settings["parent_resource"]:
|
||||
ifcopenshell.api.run(
|
||||
"nest.assign_object",
|
||||
file,
|
||||
related_objects=[resource],
|
||||
relating_object=settings["parent_resource"],
|
||||
ifcopenshell.api.nest.assign_object(
|
||||
file, related_objects=[resource], relating_object=settings["parent_resource"]
|
||||
)
|
||||
elif file.schema != "IFC2X3":
|
||||
context = file.by_type("IfcContext")[0]
|
||||
ifcopenshell.api.run(
|
||||
"project.assign_declaration",
|
||||
file,
|
||||
definitions=[resource],
|
||||
relating_context=context,
|
||||
)
|
||||
ifcopenshell.api.project.assign_declaration(file, definitions=[resource], relating_context=context)
|
||||
return resource
|
||||
|
||||
@@ -51,18 +51,18 @@ def add_resource_quantity(
|
||||
.. code:: python
|
||||
|
||||
# Add our own crew
|
||||
crew = ifcopenshell.api.run("resource.add_resource", model, ifc_class="IfcCrewResource")
|
||||
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
||||
|
||||
# Add some labour to our crew.
|
||||
labour = ifcopenshell.api.run("resource.add_resource", model,
|
||||
labour = ifcopenshell.api.resource.add_resource(model,
|
||||
parent_resource=crew, ifc_class="IfcLaborResource")
|
||||
|
||||
# Labour resource is quantified in terms of time.
|
||||
quantity = ifcopenshell.api.run("resource.add_resource_quantity", model,
|
||||
quantity = ifcopenshell.api.resource.add_resource_quantity(model,
|
||||
resource=labour, ifc_class="IfcQuantityTime")
|
||||
|
||||
# Store the time used in hours
|
||||
ifcopenshell.api.run("resource.edit_resource_quantity", model,
|
||||
ifcopenshell.api.resource.edit_resource_quantity(model,
|
||||
physical_quantity=quantity, attributes={"TimeValue": 8.0})
|
||||
"""
|
||||
settings = {"resource": resource, "ifc_class": ifc_class}
|
||||
|
||||
@@ -37,23 +37,23 @@ def add_resource_time(file: ifcopenshell.file, resource: ifcopenshell.entity_ins
|
||||
.. code:: python
|
||||
|
||||
# Add our own crew
|
||||
crew = ifcopenshell.api.run("resource.add_resource", model, ifc_class="IfcCrewResource")
|
||||
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
||||
|
||||
# Add some labour to our crew.
|
||||
labour = ifcopenshell.api.run("resource.add_resource", model,
|
||||
labour = ifcopenshell.api.resource.add_resource(model,
|
||||
parent_resource=crew, ifc_class="IfcLaborResource")
|
||||
|
||||
# Labour resource is quantified in terms of time.
|
||||
quantity = ifcopenshell.api.run("resource.add_resource_quantity", model,
|
||||
quantity = ifcopenshell.api.resource.add_resource_quantity(model,
|
||||
resource=labour, ifc_class="IfcQuantityTime")
|
||||
|
||||
# Store the unit time used in hours
|
||||
ifcopenshell.api.run("resource.edit_resource_quantity", model,
|
||||
ifcopenshell.api.resource.edit_resource_quantity(model,
|
||||
physical_quantity=quantity, attributes={"TimeValue": 8.0})
|
||||
|
||||
# Let's imagine we've used the resource for 2 days.
|
||||
time = ifcopenshell.api.run("resource.add_resource_time", model, resource=labour)
|
||||
ifcopenshell.api.run("resource.edit_resource_time", model,
|
||||
time = ifcopenshell.api.resource.add_resource_time(model, resource=labour)
|
||||
ifcopenshell.api.resource.edit_resource_time(model,
|
||||
resource_time=time, attributes={"ScheduleWork": "PT16H"})
|
||||
"""
|
||||
resource_time = file.create_entity("IfcResourceTime")
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -54,33 +54,33 @@ def assign_resource(
|
||||
.. code:: python
|
||||
|
||||
# Add our own crew
|
||||
crew = ifcopenshell.api.run("resource.add_resource", model, ifc_class="IfcCrewResource")
|
||||
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
||||
|
||||
# Add some a tower crane to our crew.
|
||||
crane = ifcopenshell.api.run("resource.add_resource", model,
|
||||
crane = ifcopenshell.api.resource.add_resource(model,
|
||||
parent_resource=crew, ifc_class="IfcConstructionEquipmentResource", name="Tower Crane 01")
|
||||
|
||||
# Our tower crane will be placed via this physical product.
|
||||
product = ifcopenshell.api.run("root.create_entity", model,
|
||||
product = ifcopenshell.api.root.create_entity(model,
|
||||
ifc_class="IfcBuildingElementProxy", predefined_type="CRANE")
|
||||
|
||||
# Let's place our crane at some X, Y coordinates.
|
||||
matrix = numpy.eye(4)
|
||||
matrix[0][3], matrix[1][3] = 3.0, 4.0
|
||||
ifcopenshell.api.run("geometry.edit_object_placement", model, product=crane, matrix=matrix)
|
||||
ifcopenshell.api.geometry.edit_object_placement(model, product=crane, matrix=matrix)
|
||||
|
||||
# Let's assign our crane to the resource. The crane now represents
|
||||
# the resource.
|
||||
ifcopenshell.api.run("resource.assign_resource", model, relating_resource=crane, related_object=product)
|
||||
ifcopenshell.api.resource.assign_resource(model, relating_resource=crane, related_object=product)
|
||||
|
||||
# Setup an organisation actor who will operate the crane
|
||||
organisation = ifcopenshell.api.run("owner.add_organisation", model,
|
||||
organisation = ifcopenshell.api.owner.add_organisation(model,
|
||||
identification="UCO", name="Unionised Crane Operators Pty Ltd")
|
||||
role = ifcopenshell.api.run("owner.add_role", model, assigned_object=organisation, role="CREW")
|
||||
actor = ifcopenshell.api.run("owner.add_actor", model, actor=organisation)
|
||||
role = ifcopenshell.api.owner.add_role(model, assigned_object=organisation, role="CREW")
|
||||
actor = ifcopenshell.api.owner.add_actor(model, actor=organisation)
|
||||
|
||||
# This means that UCO is now our crane operator.
|
||||
ifcopenshell.api.run("resource.assign_resource", model, relating_resource=crane, related_object=actor)
|
||||
ifcopenshell.api.resource.assign_resource(model, relating_resource=crane, related_object=actor)
|
||||
"""
|
||||
settings = {
|
||||
"relating_resource": relating_resource,
|
||||
@@ -103,13 +103,13 @@ def assign_resource(
|
||||
related_objects = list(resource_of.RelatedObjects)
|
||||
related_objects.append(settings["related_object"])
|
||||
resource_of.RelatedObjects = related_objects
|
||||
ifcopenshell.api.run("owner.update_owner_history", file, **{"element": resource_of})
|
||||
ifcopenshell.api.owner.update_owner_history(file, **{"element": resource_of})
|
||||
else:
|
||||
resource_of = file.create_entity(
|
||||
"IfcRelAssignsToResource",
|
||||
**{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", file),
|
||||
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(file),
|
||||
"RelatedObjects": [settings["related_object"]],
|
||||
"RelatingResource": settings["relating_resource"],
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
# 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 math
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.resource
|
||||
import ifcopenshell.util.constraint
|
||||
import ifcopenshell.util.date
|
||||
import ifcopenshell.util.element
|
||||
@@ -62,9 +61,5 @@ def calculate_resource_work(file: ifcopenshell.file, resource: ifcopenshell.enti
|
||||
if not amount_worked:
|
||||
return
|
||||
if not resource.Usage:
|
||||
ifcopenshell.api.run(
|
||||
"resource.add_resource_time",
|
||||
file,
|
||||
resource=resource,
|
||||
)
|
||||
ifcopenshell.api.resource.add_resource_time(file, resource=resource)
|
||||
resource.Usage.ScheduleWork = amount_worked
|
||||
|
||||
@@ -37,10 +37,10 @@ def edit_resource(file: ifcopenshell.file, resource: ifcopenshell.entity_instanc
|
||||
.. code:: python
|
||||
|
||||
# Add our own crew
|
||||
crew = ifcopenshell.api.run("resource.add_resource", model, ifc_class="IfcCrewResource")
|
||||
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
||||
|
||||
# Change the name of the resource to "Zone A Crew"
|
||||
ifcopenshell.api.run("resource.edit_resource", model, resource=resource, attributes={"Name": "Foo"})
|
||||
ifcopenshell.api.resource.edit_resource(model, resource=resource, attributes={"Name": "Foo"})
|
||||
"""
|
||||
settings = {"resource": resource, "attributes": attributes}
|
||||
|
||||
|
||||
@@ -39,18 +39,18 @@ def edit_resource_quantity(
|
||||
.. code:: python
|
||||
|
||||
# Add our own crew
|
||||
crew = ifcopenshell.api.run("resource.add_resource", model, ifc_class="IfcCrewResource")
|
||||
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
||||
|
||||
# Add some labour to our crew.
|
||||
labour = ifcopenshell.api.run("resource.add_resource", model,
|
||||
labour = ifcopenshell.api.resource.add_resource(model,
|
||||
parent_resource=crew, ifc_class="IfcLaborResource")
|
||||
|
||||
# Labour resource is quantified in terms of time.
|
||||
ifcopenshell.api.run("resource.add_resource_quantity", model,
|
||||
ifcopenshell.api.resource.add_resource_quantity(model,
|
||||
resource=labour, ifc_class="IfcQuantityTime")
|
||||
|
||||
# Store the time used in hours
|
||||
ifcopenshell.api.run("resource.edit_resource_quantity", model,
|
||||
ifcopenshell.api.resource.edit_resource_quantity(model,
|
||||
physical_quantity=time, attributes={"TimeValue": 8.0})
|
||||
"""
|
||||
settings = {
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
# 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 datetime
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.sequence
|
||||
from typing import Any
|
||||
|
||||
|
||||
@@ -41,23 +41,23 @@ def edit_resource_time(
|
||||
.. code:: python
|
||||
|
||||
# Add our own crew
|
||||
crew = ifcopenshell.api.run("resource.add_resource", model, ifc_class="IfcCrewResource")
|
||||
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
||||
|
||||
# Add some labour to our crew.
|
||||
labour = ifcopenshell.api.run("resource.add_resource", model,
|
||||
labour = ifcopenshell.api.resource.add_resource(model,
|
||||
parent_resource=crew, ifc_class="IfcLaborResource")
|
||||
|
||||
# Labour resource is quantified in terms of time.
|
||||
ifcopenshell.api.run("resource.add_resource_quantity", model,
|
||||
ifcopenshell.api.resource.add_resource_quantity(model,
|
||||
resource=labour, ifc_class="IfcQuantityTime")
|
||||
|
||||
# Store the unit time used in hours
|
||||
ifcopenshell.api.run("resource.edit_resource_quantity", model,
|
||||
ifcopenshell.api.resource.edit_resource_quantity(model,
|
||||
physical_quantity=time, attributes={"TimeValue": 8.0})
|
||||
|
||||
# Let's imagine we've used the resource for 2 days.
|
||||
time = ifcopenshell.api.run("resource.add_resource_time", model, resource=labour)
|
||||
ifcopenshell.api.run("resource.edit_resource_time", model,
|
||||
time = ifcopenshell.api.resource.add_resource_time(model, resource=labour)
|
||||
ifcopenshell.api.resource.edit_resource_time(model,
|
||||
resource_time=time, attributes={"ScheduleWork": "P16H"})
|
||||
"""
|
||||
usecase = Usecase()
|
||||
@@ -94,7 +94,7 @@ class Usecase:
|
||||
):
|
||||
task = ifcopenshell.util.resource.get_task_assignments(self.resource)
|
||||
if task:
|
||||
ifcopenshell.api.run("sequence.calculate_task_duration", self.file, task=task)
|
||||
ifcopenshell.api.sequence.calculate_task_duration(self.file, task=task)
|
||||
|
||||
def get_resource(self):
|
||||
return [e for e in self.file.get_inverse(self.settings["resource_time"]) if e.is_a("IfcResource")][0]
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.resource
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
@@ -29,10 +29,10 @@ def remove_resource(file: ifcopenshell.file, resource: ifcopenshell.entity_insta
|
||||
.. code:: python
|
||||
|
||||
# Add our own crew
|
||||
crew = ifcopenshell.api.run("resource.add_resource", model, ifc_class="IfcCrewResource")
|
||||
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
||||
|
||||
# Fire our crew
|
||||
ifcopenshell.api.run("resource.remove_resource", model, resource=crew)
|
||||
ifcopenshell.api.resource.remove_resource(model, resource=crew)
|
||||
"""
|
||||
settings = {"resource": resource}
|
||||
|
||||
@@ -41,11 +41,7 @@ def remove_resource(file: ifcopenshell.file, resource: ifcopenshell.entity_insta
|
||||
if inverse.is_a("IfcRelNests"):
|
||||
if inverse.RelatingObject == settings["resource"]:
|
||||
for related_object in inverse.RelatedObjects:
|
||||
ifcopenshell.api.run(
|
||||
"resource.remove_resource",
|
||||
file,
|
||||
resource=related_object,
|
||||
)
|
||||
ifcopenshell.api.resource.remove_resource(file, resource=related_object)
|
||||
history = inverse.OwnerHistory
|
||||
file.remove(inverse)
|
||||
if history:
|
||||
@@ -63,11 +59,8 @@ def remove_resource(file: ifcopenshell.file, resource: ifcopenshell.entity_insta
|
||||
elif inverse.is_a("IfcRelAssignsToResource"):
|
||||
if inverse.RelatingResource == settings["resource"]:
|
||||
for related_object in inverse.RelatedObjects:
|
||||
ifcopenshell.api.run(
|
||||
"resource.unassign_resource",
|
||||
file,
|
||||
related_object=related_object,
|
||||
resource=settings["resource"],
|
||||
ifcopenshell.api.resource.unassign_resource(
|
||||
file, related_object=related_object, relating_resource=settings["resource"]
|
||||
)
|
||||
elif inverse.RelatedObjects == tuple(settings["resource"]):
|
||||
history = inverse.OwnerHistory
|
||||
@@ -78,11 +71,7 @@ def remove_resource(file: ifcopenshell.file, resource: ifcopenshell.entity_insta
|
||||
if usage := getattr(settings["resource"], "Usage", None):
|
||||
file.remove(usage)
|
||||
if settings["resource"].BaseQuantity:
|
||||
ifcopenshell.api.run(
|
||||
"resource.remove_resource_quantity",
|
||||
file,
|
||||
resource=settings["resource"],
|
||||
)
|
||||
ifcopenshell.api.resource.remove_resource_quantity(file, resource=settings["resource"])
|
||||
history = settings["resource"].OwnerHistory
|
||||
file.remove(settings["resource"])
|
||||
if history:
|
||||
|
||||
@@ -27,19 +27,19 @@ def remove_resource_quantity(file: ifcopenshell.file, resource: ifcopenshell.ent
|
||||
.. code:: python
|
||||
|
||||
# Add our own crew
|
||||
crew = ifcopenshell.api.run("resource.add_resource", model, ifc_class="IfcCrewResource")
|
||||
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
||||
|
||||
# Add some labour to our crew.
|
||||
labour = ifcopenshell.api.run("resource.add_resource", model,
|
||||
labour = ifcopenshell.api.resource.add_resource(model,
|
||||
parent_resource=crew, ifc_class="IfcLaborResource")
|
||||
|
||||
# Labour resource is quantified in terms of time.
|
||||
ifcopenshell.api.run("resource.add_resource_quantity", model,
|
||||
ifcopenshell.api.resource.add_resource_quantity(model,
|
||||
resource=labour, ifc_class="IfcQuantityTime")
|
||||
|
||||
# Let's say we only want to store the resource but no quantities,
|
||||
# let's clean up our mess and remove the quantity.
|
||||
ifcopenshell.api.run("resource.remove_resource_quantity", model, resource=labour)
|
||||
ifcopenshell.api.resource.remove_resource_quantity(model, resource=labour)
|
||||
"""
|
||||
settings = {"resource": resource}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -41,23 +41,23 @@ def unassign_resource(
|
||||
.. code:: python
|
||||
|
||||
# Add our own crew
|
||||
crew = ifcopenshell.api.run("resource.add_resource", model, ifc_class="IfcCrewResource")
|
||||
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
||||
|
||||
# Add some a tower crane to our crew.
|
||||
crane = ifcopenshell.api.run("resource.add_resource", model,
|
||||
crane = ifcopenshell.api.resource.add_resource(model,
|
||||
parent_resource=crew, ifc_class="IfcConstructionEquipmentResource", name="Tower Crane 01")
|
||||
|
||||
# Our tower crane will be placed via this physical product.
|
||||
product = ifcopenshell.api.run("root.create_entity", model,
|
||||
product = ifcopenshell.api.root.create_entity(model,
|
||||
ifc_class="IfcBuildingElementProxy", predefined_type="CRANE")
|
||||
|
||||
# Let's assign our crane to the resource. The crane now represents
|
||||
# the resource.
|
||||
ifcopenshell.api.run("resource.assign_resource", model,
|
||||
ifcopenshell.api.resource.assign_resource(model,
|
||||
relating_resource=crane, related_object=product)
|
||||
|
||||
# Undo it.
|
||||
ifcopenshell.api.run("resource.unassign_resource", model,
|
||||
ifcopenshell.api.resource.unassign_resource(model,
|
||||
relating_resource=crane, related_object=product)
|
||||
"""
|
||||
settings = {
|
||||
@@ -77,4 +77,4 @@ def unassign_resource(
|
||||
related_objects = list(rel.RelatedObjects)
|
||||
related_objects.remove(settings["related_object"])
|
||||
rel.RelatedObjects = related_objects
|
||||
ifcopenshell.api.run("owner.update_owner_history", file, **{"element": rel})
|
||||
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
|
||||
|
||||
Reference in New Issue
Block a user