replace api.run with static methods

This commit is contained in:
Andrej
2025-06-09 10:59:22 +05:00
parent 02d359d0e6
commit 8b4683aef1
122 changed files with 1334 additions and 1370 deletions
+11 -10
View File
@@ -143,6 +143,9 @@ reload_event = False
from os.path import splitext
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.aggregate
import ifcopenshell.api.root
import ifcopenshell.api.spatial
import ifcopenshell.util.element
from ifcsverchok.ifcstore import SvIfcStore
@@ -201,7 +204,7 @@ class IFC_Sv_write_file(bpy.types.Operator, ExportHelper):
def ensure_hirarchy(self, file: ifcopenshell.file) -> None:
elements_in_buildings: set[ifcopenshell.entity_instance] = set()
if len(file.by_type("IfcBuilding")) == 0:
my_building = ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcBuilding", name="My Building")
my_building = ifcopenshell.api.root.create_entity(file, ifc_class="IfcBuilding", name="My Building")
elements = ifcopenshell.util.element.get_decomposition(my_building)
else:
for building in file.by_type("IfcBuilding"):
@@ -211,8 +214,8 @@ class IFC_Sv_write_file(bpy.types.Operator, ExportHelper):
for spatial in file.by_type("IfcSpatialElement") or file.by_type("IfcSpatialStructureElement"):
if not (spatial.is_a("IfcSite") or spatial.is_a("IfcBuilding")) and (spatial not in elements_in_buildings):
elements = ifcopenshell.util.element.get_decomposition(spatial)
ifcopenshell.api.run(
"aggregate.assign_object", file, products=[spatial], relating_object=file.by_type("IfcBuilding")[0]
ifcopenshell.api.aggregate.assign_object(
file, products=[spatial], relating_object=file.by_type("IfcBuilding")[0]
)
for building in file.by_type("IfcBuilding"):
@@ -222,8 +225,7 @@ class IFC_Sv_write_file(bpy.types.Operator, ExportHelper):
elements = file.by_type("IfcElement")
for element in elements:
if element not in elements_in_buildings:
ifcopenshell.api.run(
"spatial.assign_container",
ifcopenshell.api.spatial.assign_container(
file,
products=[element],
relating_structure=file.by_type("IfcBuilding")[0],
@@ -233,17 +235,16 @@ class IFC_Sv_write_file(bpy.types.Operator, ExportHelper):
elements = ifcopenshell.util.element.get_decomposition(building)
if not building.Decomposes:
if len(file.by_type("IfcSite")) == 0:
ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcSite", name="My Site")
ifcopenshell.api.run(
"aggregate.assign_object", file, products=[building], relating_object=file.by_type("IfcSite")[0]
ifcopenshell.api.root.create_entity(file, ifc_class="IfcSite", name="My Site")
ifcopenshell.api.aggregate.assign_object(
file, products=[building], relating_object=file.by_type("IfcSite")[0]
)
try:
if file.by_type("IfcSite")[0].Decomposes[0].RelatingObject.is_a("IfcProject"):
continue
except IndexError:
pass
ifcopenshell.api.run(
"aggregate.assign_object",
ifcopenshell.api.aggregate.assign_object(
file,
products=[file.by_type("IfcSite")[0]],
relating_object=file.by_type("IfcProject")[0],