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