From 0234809d0b2bfe216b07c3c89064151bc29f686d Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 5 Feb 2026 12:13:02 +0500 Subject: [PATCH] Prefer direct api calls over `tool.Ifc.run` --- .../bonsai/bim/module/system/operator.py | 8 ++++--- src/bonsai/bonsai/tool/project.py | 24 ++++++++++--------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/system/operator.py b/src/bonsai/bonsai/bim/module/system/operator.py index 089bd9f24b..d365964968 100644 --- a/src/bonsai/bonsai/bim/module/system/operator.py +++ b/src/bonsai/bonsai/bim/module/system/operator.py @@ -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 diff --git a/src/bonsai/bonsai/tool/project.py b/src/bonsai/bonsai/tool/project.py index da613c3fa9..fc1e4d5e77 100644 --- a/src/bonsai/bonsai/tool/project.py +++ b/src/bonsai/bonsai/tool/project.py @@ -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)