Prefer direct api calls over tool.Ifc.run

This commit is contained in:
Andrej730
2026-02-05 12:13:02 +05:00
parent 38381f44b9
commit 0234809d0b
2 changed files with 18 additions and 14 deletions
@@ -20,6 +20,7 @@ from typing import TYPE_CHECKING
import bpy
import ifcopenshell.api
import ifcopenshell.api.attribute
import ifcopenshell.api.system
import ifcopenshell.util.system
@@ -445,6 +446,7 @@ class CycleFlowDirection(bpy.types.Operator, tool.Ifc.Operator):
return "Cycle through flow directions: SOURCE → SINK → SOURCEANDSINK → NOTDEFINED → SOURCE..."
def _execute(self, context):
ifc_file = tool.Ifc.get()
port = tool.Ifc.get().by_id(self.port_id)
if not port or not port.is_a("IfcDistributionPort"):
return {"CANCELLED"}
@@ -459,7 +461,7 @@ class CycleFlowDirection(bpy.types.Operator, tool.Ifc.Operator):
}
next_direction = flow_cycle_map.get(current_direction, "SOURCE")
tool.Ifc.run("attribute.edit_attributes", product=port, attributes={"FlowDirection": next_direction})
ifcopenshell.api.attribute.edit_attributes(ifc_file, product=port, attributes={"FlowDirection": next_direction})
connected_port = tool.System.get_connected_port(port)
if connected_port:
@@ -470,8 +472,8 @@ class CycleFlowDirection(bpy.types.Operator, tool.Ifc.Operator):
"NOTDEFINED": "NOTDEFINED",
}
connected_direction = connected_direction_map.get(next_direction, "NOTDEFINED")
tool.Ifc.run(
"attribute.edit_attributes", product=connected_port, attributes={"FlowDirection": connected_direction}
ifcopenshell.api.attribute.edit_attributes(
ifc_file, product=connected_port, attributes={"FlowDirection": connected_direction}
)
PortData.is_loaded = False
+13 -11
View File
@@ -542,11 +542,11 @@ class Project(bonsai.core.tool.Project):
if not ifc_file:
raise Exception("No IFC file loaded")
doc = tool.Ifc.run("document.add_information", parent=None)
doc = ifcopenshell.api.document.add_information(ifc_file, parent=None)
if ifc_file.schema == "IFC2X3":
tool.Ifc.run(
"document.edit_information",
ifcopenshell.api.document.edit_information(
ifc_file,
information=doc,
attributes={
"DocumentId": "BLEND_METADATA",
@@ -557,8 +557,8 @@ class Project(bonsai.core.tool.Project):
},
)
else:
tool.Ifc.run(
"document.edit_information",
ifcopenshell.api.document.edit_information(
ifc_file,
information=doc,
attributes={
"Identification": "BLEND_METADATA",
@@ -578,13 +578,15 @@ class Project(bonsai.core.tool.Project):
return
ifc_file = tool.Ifc.get()
if not ifc_file:
return
tool.Ifc.run("document.edit_information", information=doc, attributes={"Location": metadata_filename})
ifcopenshell.api.document.edit_information(
ifc_file, information=doc, attributes={"Location": metadata_filename}
)
@classmethod
def remove_metadata_document_information(cls) -> None:
doc = cls.get_metadata_document_information()
if doc:
tool.Ifc.run("document.remove_information", information=doc)
if not doc:
return
ifc_file = tool.Ifc.get()
ifcopenshell.api.document.remove_information(ifc_file, information=doc)