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
@@ -19,7 +19,8 @@
RUN_FROM_DEV_REPO = False
import ifcopenshell.ifcopenshell_wrapper as ifcopenshell_wrapper
import ifcopenshell.api
import ifcopenshell.api.unit
import ifcopenshell.api.project
import ifcopenshell.guid
import ifcopenshell.util.attribute
import glob
@@ -123,7 +124,7 @@ class PsetTemplatesGenerator:
def parse_psets_data(self, schema_name, pset_data_glob, project_name, ifc_output_path):
schema_name = schema_name.upper()
self.ifc_file = ifcopenshell.api.run("project.create_file", version=schema_name)
self.ifc_file = ifcopenshell.api.project.create_file(version=schema_name)
self.units = dict()
schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(schema_name)
@@ -268,13 +269,13 @@ class PsetTemplatesGenerator:
unit_entity = None
if unit_type in self.ifc_derived_unit_enum:
# TODO: define derived units if there will be someday api like `ifcopenshell.api.run("unit.add_derived_unit", ...)`
# TODO: define derived units if there will be someday api like `ifcopenshell.api.unit.add_derived_unit(...)`
# since creating IfcDerivedUnit is more complex and requiring settting up elements it consists of
# and related IfcNamedUnits
# unit_entity = ifcopenshell.api.run("unit.add_derived_unit", self.ifc_file, unit_type=unit_type)
# unit_entity = ifcopenshell.api.unit.add_derived_unit(self.ifc_file, unit_type=unit_type)
pass
elif unit_type in self.ifc_unit_enum:
unit_entity = ifcopenshell.api.run("unit.add_si_unit", self.ifc_file, unit_type=unit_type)
unit_entity = ifcopenshell.api.unit.add_si_unit(self.ifc_file, unit_type=unit_type)
elif unit_type == "IFCMONETARYUNIT":
self.ifc_entity("IFCMONETARYUNIT", Currency="")
else:
@@ -19,7 +19,8 @@
import re
import lark
import numpy as np
import ifcopenshell.api
import ifcopenshell.api.pset
import ifcopenshell.api.geometry
import ifcopenshell.util
import ifcopenshell.util.attribute
import ifcopenshell.util.fm
@@ -522,9 +523,7 @@ def set_element_value(
return
matrix[coord_i][3] = new_value
ifcopenshell.api.run(
"geometry.edit_object_placement", ifc_file, product=element, matrix=matrix, is_si=False
)
ifcopenshell.api.geometry.edit_object_placement(ifc_file, product=element, matrix=matrix, is_si=False)
return
elif isinstance(element, ifcopenshell.entity_instance):
if key == "Name" and element.is_a("IfcMaterialLayerSet"):
@@ -584,9 +583,9 @@ def set_element_value(
if value and not result and len(keys) == i + 2: # The next key is the prop name
if "qto" in key.lower() or "quantity" in key.lower() or "quantities" in key.lower():
pset = ifcopenshell.api.run("pset.add_qto", ifc_file, product=element, name=key)
pset = ifcopenshell.api.pset.add_qto(ifc_file, product=element, name=key)
else:
pset = ifcopenshell.api.run("pset.add_pset", ifc_file, product=element, name=key)
pset = ifcopenshell.api.pset.add_pset(ifc_file, product=element, name=key)
result = {"id": pset.id()}
element = result
@@ -596,16 +595,16 @@ def set_element_value(
for prop, prop_value in element.items():
if key.match(prop):
if pset.is_a("IfcPropertySet") and prop_value != value:
ifcopenshell.api.run("pset.edit_pset", ifc_file, pset=pset, properties={prop: value})
ifcopenshell.api.pset.edit_pset(ifc_file, pset=pset, properties={prop: value})
elif pset.is_a("IfcElementQuantity") and prop_value != float(value):
ifcopenshell.api.run("pset.edit_qto", ifc_file, qto=pset, properties={prop: float(value)})
ifcopenshell.api.pset.edit_qto(ifc_file, qto=pset, properties={prop: float(value)})
elif pset.is_a("IfcPropertySet") and element.get(key, None) != value:
ifcopenshell.api.run("pset.edit_pset", ifc_file, pset=pset, properties={key: value})
ifcopenshell.api.pset.edit_pset(ifc_file, pset=pset, properties={key: value})
elif pset.is_a("IfcElementQuantity"):
try:
value = float(value)
if element.get(key, None) != value:
ifcopenshell.api.run("pset.edit_qto", ifc_file, qto=pset, properties={key: value})
ifcopenshell.api.pset.edit_qto(ifc_file, qto=pset, properties={key: value})
except:
pass
return
@@ -500,18 +500,18 @@ def get_related_products(
# Let's imagine we are creating a construction schedule. All tasks
# need to be part of a work schedule.
schedule = ifcopenshell.api.run("sequence.add_work_schedule", model, name="Construction Schedule A")
schedule = ifcopenshell.api.sequence.add_work_schedule(model, name="Construction Schedule A")
# Let's create a construction task. Note that the predefined type is
# important to distinguish types of tasks.
task = ifcopenshell.api.run("sequence.add_task", model,
task = ifcopenshell.api.sequence.add_task(model,
work_schedule=schedule, name="Build wall", identification="A", predefined_type="CONSTRUCTION")
# Let's say we have a wall somewhere.
wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
# Let's construct that wall!
ifcopenshell.api.run("sequence.assign_product", relating_product=wall, related_object=task)
ifcopenshell.api.sequence.assign_product(relating_product=wall, related_object=task)
# This will give us a set with that wall in it.
products = ifcopenshell.util.sequence.get_related_products(related_object=task)
@@ -22,7 +22,7 @@ from typing import Iterable, Any, Union, Literal, Optional
import ifcopenshell
import ifcopenshell.ifcopenshell_wrapper as ifcopenshell_wrapper
import ifcopenshell.api
import ifcopenshell.api.unit
prefixes = {
"EXA": 1e18,
@@ -815,7 +815,7 @@ def convert_file_length_units(ifc_file: ifcopenshell.file, target_units: str = "
old_length = next(u for u in unit_assignment.Units if getattr(u, "UnitType", None) == "LENGTHUNIT")
if si_unit:
new_length = ifcopenshell.api.run("unit.add_si_unit", file_patched, unit_type="LENGTHUNIT", prefix=prefix)
new_length = ifcopenshell.api.unit.add_si_unit(file_patched, unit_type="LENGTHUNIT", prefix=prefix)
else:
target_units = target_units.lower()
if imperial_types.get(target_units) != "LENGTHUNIT":
@@ -823,7 +823,7 @@ def convert_file_length_units(ifc_file: ifcopenshell.file, target_units: str = "
f'Couldn\'t identify target units "{target_units}". '
'The method supports singular unit names like "CENTIMETER", "METER", "FOOT", etc.'
)
new_length = ifcopenshell.api.run("unit.add_conversion_based_unit", file_patched, name=target_units)
new_length = ifcopenshell.api.unit.add_conversion_based_unit(file_patched, name=target_units)
# support tuple of tuples, as in IfcCartesianPointList3D.CoordList
def convert_value(value):