ifcsverchok - operator to apply graph to Bonsai file

This commit is contained in:
Andrej730
2026-01-15 16:54:37 +05:00
parent 413530bb0a
commit 47e259ff2f
5 changed files with 51 additions and 0 deletions
@@ -22,6 +22,7 @@ from . import ui, prop, operator
classes = (
operator.DrawSystemArrows,
operator.GetConnectedSystemElements,
operator.IfcSverchokUseBonsaiFile,
operator.ResizeToStorey,
operator.SetOverrideColour,
operator.SnapSpacesTogether,
@@ -348,3 +348,24 @@ class DrawSystemArrows(bpy.types.Operator, tool.Ifc.Operator):
)
)
return matrix
class IfcSverchokUseBonsaiFile(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.ifcsverchok_use_bonsai_file"
bl_label = "Use Bonsai IFC File"
bl_description = "Apply current IfcSverchok tree to the active Bonsai file."
bl_options = {"REGISTER", "UNDO"}
def _execute(self, context):
import sverchok.node_tree
ifc_file = tool.Ifc.get()
if ifc_file is None:
self.report({"ERROR"}, "No active IFC file.")
return {"CANCELLED"}
space_data = context.space_data
assert isinstance(space_data, bpy.types.SpaceNodeEditor)
node_tree = space_data.node_tree
assert isinstance(node_tree, sverchok.node_tree.SverchCustomTree)
tool.Model.run_ifcsverchok_graph_on_bonsai_file(node_tree)
+22
View File
@@ -2669,3 +2669,25 @@ class Model(bonsai.core.tool.Model):
material.OffsetFromReferenceLine = custom_offset
cls.recreate_wall(element, wall)
@classmethod
def run_ifcsverchok_graph_on_bonsai_file(cls, node_tree: sverchok.node_tree.SverchCustomTree) -> None:
from ifcsverchok.ifcstore import SvIfcStore
from sverchok.core.update_system import UpdateTree
# We should be very careful and use bonsai file just for 1 graph update.
# To avoid producing duplicated data in non-ephemeral file.
SvIfcStore.use_bonsai_file = True
try:
# The ones below refresh asyncronously, so we're using different method to get results synchronously.
# - bpy.ops.node.sverchok_update_context(force_mode=True)
# - node_tree.force_update()
# TODO: Ideally we should find shape output node and update only it's furtherest children.
# Because user might have some nodes just floating around unused.
# ` update_tree = UpdateTree.get(node_tree); update_tree.add_outdated(nodes)` can be used for this.
UpdateTree.reset_tree(node_tree)
nodes_to_update = UpdateTree.main_update(node_tree)
# Consuming generator, which triggers the update.
list(nodes_to_update)
finally:
SvIfcStore.use_bonsai_file = False
+2
View File
@@ -297,11 +297,13 @@ class IFC_PT_write_file_panel(bpy.types.Panel):
def draw(self, context):
ng = context.space_data.node_tree
layout = self.layout
assert layout
row = layout.split(factor=0.2, align=True)
row = layout.row()
row2 = layout.row()
row.operator("ifc.sverchok_update_current", text="IFC Re-run all nodes")
row2.operator("ifc.write_file_panel")
layout.operator("bim.ifcsverchok_use_bonsai_file")
CLASSES = [IFC_Sv_UpdateCurrent, IFC_Sv_write_file, IFC_PT_write_file_panel]
+5
View File
@@ -18,6 +18,7 @@
from typing import Any, Union
import bonsai.tool as tool
import bpy
import ifcopenshell
import ifcopenshell.api
@@ -50,6 +51,8 @@ class SvIfcStore:
future = []
schema_identifiers = ["IFC4", "IFC2X3"]
use_bonsai_file = False
@staticmethod
def purge() -> None:
SvIfcStore.path = ""
@@ -95,6 +98,8 @@ class SvIfcStore:
@staticmethod
def get_file() -> ifcopenshell.file:
if SvIfcStore.use_bonsai_file:
return tool.Ifc.get()
if SvIfcStore.file is None:
SvIfcStore.create_boilerplate()
return SvIfcStore.file