mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 22:11:36 +00:00
replace api.run with static methods
This commit is contained in:
@@ -22,6 +22,9 @@ from itertools import chain
|
||||
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.aggregate
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.spatial
|
||||
import ifcopenshell.util.element
|
||||
import ifcsverchok.helper
|
||||
from ifcsverchok.ifcstore import SvIfcStore
|
||||
@@ -124,23 +127,20 @@ class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
|
||||
if index is not None:
|
||||
iterator = [index]
|
||||
for i in iterator:
|
||||
result = ifcopenshell.api.run(
|
||||
"root.create_entity",
|
||||
result = ifcopenshell.api.root.create_entity(
|
||||
self.file,
|
||||
name=self.names[i],
|
||||
ifc_class=self.ifc_class,
|
||||
)
|
||||
for items in self.elements[i]:
|
||||
if items.is_a("IfcSpatialElement") or items.is_a("IfcSpatialStructureElement"):
|
||||
ifcopenshell.api.run(
|
||||
"aggregate.assign_object",
|
||||
ifcopenshell.api.aggregate.assign_object(
|
||||
self.file,
|
||||
products=[items],
|
||||
relating_object=result,
|
||||
)
|
||||
else:
|
||||
ifcopenshell.api.run(
|
||||
"spatial.assign_container",
|
||||
ifcopenshell.api.spatial.assign_container(
|
||||
self.file,
|
||||
products=[items],
|
||||
relating_structure=result,
|
||||
@@ -170,30 +170,26 @@ class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
|
||||
if removed_element.is_a("IfcSpatialElement") or removed_element.is_a(
|
||||
"IfcSpatialStructureElement"
|
||||
):
|
||||
ifcopenshell.api.run(
|
||||
"aggregate.unassign_object",
|
||||
ifcopenshell.api.aggregate.unassign_object(
|
||||
self.file,
|
||||
products=[removed_element],
|
||||
relating_object=result,
|
||||
)
|
||||
else:
|
||||
ifcopenshell.api.run(
|
||||
"spatial.unassign_container",
|
||||
ifcopenshell.api.spatial.unassign_container(
|
||||
self.file,
|
||||
products=[removed_element],
|
||||
relating_object=result,
|
||||
)
|
||||
for added_element in element_set - subelements:
|
||||
if added_element.is_a("IfcSpatialElement") or added_element.is_a("IfcSpatialStructureElement"):
|
||||
ifcopenshell.api.run(
|
||||
"aggregate.assign_object",
|
||||
ifcopenshell.api.aggregate.assign_object(
|
||||
self.file,
|
||||
products=[added_element],
|
||||
relating_object=result,
|
||||
)
|
||||
else:
|
||||
ifcopenshell.api.run(
|
||||
"spatial.assign_container",
|
||||
ifcopenshell.api.spatial.assign_container(
|
||||
self.file,
|
||||
products=[added_element],
|
||||
relating_structure=result,
|
||||
@@ -206,7 +202,7 @@ class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
|
||||
if self.node_id in SvIfcStore.id_map:
|
||||
for element_id in SvIfcStore.id_map[self.node_id]:
|
||||
element = self.file.by_id(element_id)
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=element)
|
||||
ifcopenshell.api.root.remove_product(self.file, product=element)
|
||||
del SvIfcStore.id_map[self.node_id]
|
||||
|
||||
def repeat_input_unique(self, input, count):
|
||||
|
||||
@@ -23,6 +23,7 @@ import bpy
|
||||
import ifcopenshell
|
||||
import ifcsverchok.helper
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.geometry
|
||||
import ifcopenshell.util.representation
|
||||
from ifcsverchok.ifcstore import SvIfcStore
|
||||
@@ -224,8 +225,7 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
|
||||
return
|
||||
for obj in SvIfcStore.id_map[self.node_id]["Representations"]:
|
||||
for step_id in obj:
|
||||
ifcopenshell.api.run(
|
||||
"geometry.remove_representation",
|
||||
ifcopenshell.api.geometry.remove_representation(
|
||||
self.file,
|
||||
representation=self.file.by_id(step_id[0]),
|
||||
)
|
||||
@@ -240,9 +240,8 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
|
||||
if not context:
|
||||
parent = ifcopenshell.util.representation.get_context(self.file, self.context_type)
|
||||
if not parent:
|
||||
parent = ifcopenshell.api.run("context.add_context", self.file, context_type=self.context_type)
|
||||
context = ifcopenshell.api.run(
|
||||
"context.add_context",
|
||||
parent = ifcopenshell.api.context.add_context(self.file, context_type=self.context_type)
|
||||
context = ifcopenshell.api.context.add_context(
|
||||
self.file,
|
||||
context_type=self.context_type,
|
||||
context_identifier=self.context_identifier,
|
||||
@@ -258,8 +257,7 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
|
||||
if "Representations" in SvIfcStore.id_map[self.node_id]:
|
||||
for obj in SvIfcStore.id_map[self.node_id]["Representations"]:
|
||||
for step_id in obj:
|
||||
ifcopenshell.api.run(
|
||||
"geometry.remove_representation",
|
||||
ifcopenshell.api.geometry.remove_representation(
|
||||
self.file,
|
||||
representation=self.file.by_id(step_id),
|
||||
)
|
||||
@@ -270,10 +268,10 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
|
||||
if not self.file.get_inverse(context):
|
||||
if self.file.by_id(context_id).ParentContext:
|
||||
parent = self.file.by_id(context_id).ParentContext
|
||||
ifcopenshell.api.run("context.remove_context", self.file, context=context)
|
||||
ifcopenshell.api.context.remove_context(self.file, context=context)
|
||||
if parent:
|
||||
if not self.file.get_inverse(parent):
|
||||
ifcopenshell.api.run("context.remove_context", self.file, context=parent)
|
||||
ifcopenshell.api.context.remove_context(self.file, context=parent)
|
||||
SvIfcStore.id_map[self.node_id]["Contexts"].remove(context_id)
|
||||
del SvIfcStore.id_map[self.node_id]
|
||||
del self.node_dict[hash(self)]
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.unit
|
||||
import ifcsverchok.helper
|
||||
import ifcsverchok.helper as helper
|
||||
from sverchok.node_tree import SverchCustomTreeNode
|
||||
@@ -59,12 +62,11 @@ class SvIfcCreateProject(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helpe
|
||||
|
||||
def process_ifc(self, file: ifcopenshell.file, project_name: str) -> None:
|
||||
# create project
|
||||
project = ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcProject", name=str(project_name))
|
||||
lengthunit = ifcopenshell.api.run("unit.add_si_unit", file, unit_type="LENGTHUNIT")
|
||||
ifcopenshell.api.run("unit.assign_unit", file, units=[lengthunit])
|
||||
model = ifcopenshell.api.run("context.add_context", file, context_type="Model")
|
||||
context = ifcopenshell.api.run(
|
||||
"context.add_context",
|
||||
project = ifcopenshell.api.root.create_entity(file, ifc_class="IfcProject", name=str(project_name))
|
||||
lengthunit = ifcopenshell.api.unit.add_si_unit(file, unit_type="LENGTHUNIT")
|
||||
ifcopenshell.api.unit.assign_unit(file, units=[lengthunit])
|
||||
model = ifcopenshell.api.context.add_context(file, context_type="Model")
|
||||
context = ifcopenshell.api.context.add_context(
|
||||
file,
|
||||
context_type="Model",
|
||||
context_identifier="Body",
|
||||
|
||||
@@ -20,6 +20,9 @@ from os.path import abspath, splitext
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.aggregate
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.spatial
|
||||
import ifcopenshell.util.element
|
||||
import ifcsverchok.helper
|
||||
import ifcsverchok.helper as helper
|
||||
@@ -96,7 +99,7 @@ class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.Sv
|
||||
# TODO: same code as ifc.write_file_panel?
|
||||
elements_in_buildings = []
|
||||
if not 0 <= 0 < len(file.by_type("IfcBuilding")):
|
||||
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"):
|
||||
@@ -106,8 +109,7 @@ class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.Sv
|
||||
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",
|
||||
ifcopenshell.api.aggregate.assign_object(
|
||||
file,
|
||||
products=[spatial],
|
||||
relating_object=file.by_type("IfcBuilding")[0],
|
||||
@@ -121,8 +123,7 @@ class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.Sv
|
||||
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],
|
||||
@@ -132,9 +133,8 @@ class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.Sv
|
||||
elements = ifcopenshell.util.element.get_decomposition(building)
|
||||
if not building.Decomposes:
|
||||
if not 0 <= 0 < len(file.by_type("IfcSite")):
|
||||
ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcSite", name="My Site")
|
||||
ifcopenshell.api.run(
|
||||
"aggregate.assign_object",
|
||||
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],
|
||||
@@ -144,8 +144,7 @@ class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.Sv
|
||||
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],
|
||||
|
||||
Reference in New Issue
Block a user