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 bpy
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.api.attribute
import ifcopenshell.api.system import ifcopenshell.api.system
import ifcopenshell.util.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..." return "Cycle through flow directions: SOURCE → SINK → SOURCEANDSINK → NOTDEFINED → SOURCE..."
def _execute(self, context): def _execute(self, context):
ifc_file = tool.Ifc.get()
port = tool.Ifc.get().by_id(self.port_id) port = tool.Ifc.get().by_id(self.port_id)
if not port or not port.is_a("IfcDistributionPort"): if not port or not port.is_a("IfcDistributionPort"):
return {"CANCELLED"} return {"CANCELLED"}
@@ -459,7 +461,7 @@ class CycleFlowDirection(bpy.types.Operator, tool.Ifc.Operator):
} }
next_direction = flow_cycle_map.get(current_direction, "SOURCE") 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) connected_port = tool.System.get_connected_port(port)
if connected_port: if connected_port:
@@ -470,8 +472,8 @@ class CycleFlowDirection(bpy.types.Operator, tool.Ifc.Operator):
"NOTDEFINED": "NOTDEFINED", "NOTDEFINED": "NOTDEFINED",
} }
connected_direction = connected_direction_map.get(next_direction, "NOTDEFINED") connected_direction = connected_direction_map.get(next_direction, "NOTDEFINED")
tool.Ifc.run( ifcopenshell.api.attribute.edit_attributes(
"attribute.edit_attributes", product=connected_port, attributes={"FlowDirection": connected_direction} ifc_file, product=connected_port, attributes={"FlowDirection": connected_direction}
) )
PortData.is_loaded = False PortData.is_loaded = False
+13 -11
View File
@@ -542,11 +542,11 @@ class Project(bonsai.core.tool.Project):
if not ifc_file: if not ifc_file:
raise Exception("No IFC file loaded") 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": if ifc_file.schema == "IFC2X3":
tool.Ifc.run( ifcopenshell.api.document.edit_information(
"document.edit_information", ifc_file,
information=doc, information=doc,
attributes={ attributes={
"DocumentId": "BLEND_METADATA", "DocumentId": "BLEND_METADATA",
@@ -557,8 +557,8 @@ class Project(bonsai.core.tool.Project):
}, },
) )
else: else:
tool.Ifc.run( ifcopenshell.api.document.edit_information(
"document.edit_information", ifc_file,
information=doc, information=doc,
attributes={ attributes={
"Identification": "BLEND_METADATA", "Identification": "BLEND_METADATA",
@@ -578,13 +578,15 @@ class Project(bonsai.core.tool.Project):
return return
ifc_file = tool.Ifc.get() ifc_file = tool.Ifc.get()
if not ifc_file: ifcopenshell.api.document.edit_information(
return ifc_file, information=doc, attributes={"Location": metadata_filename}
)
tool.Ifc.run("document.edit_information", information=doc, attributes={"Location": metadata_filename})
@classmethod @classmethod
def remove_metadata_document_information(cls) -> None: def remove_metadata_document_information(cls) -> None:
doc = cls.get_metadata_document_information() doc = cls.get_metadata_document_information()
if doc: if not doc:
tool.Ifc.run("document.remove_information", information=doc) return
ifc_file = tool.Ifc.get()
ifcopenshell.api.document.remove_information(ifc_file, information=doc)