用途:从 Python 脚本外部控制 Sverchok 节点树,实现程序化创建、修改、查询与批量处理,适用于参数化建模与批量参数研究。
主要能力:通过 bpy.data.node_groups 按 bl_idname='SverchCustomTreeType' 访问节点树;用 tree.nodes.new(bl_idname) 创建节点并设置 location 与属性;用 tree.links.new(output_socket, input_socket) 连接插槽;用 tree.force_update()、tree.update_nodes() 触发求值;用 node.outputs[name].sv_get() 读取计算结果;用 setattr() 加 force_update() 循环做参数扫描;用 tree.init_tree() 上下文管理器抑制中间更新以提升性能;从 sverchok.data_structure 导入 match_long_repeat、fullList、repeat_last 等数据匹配工具。
必要用法与限制:创建节点或连接时必须使用 tree.init_tree() 上下文管理器,否则每次调用都会触发整树重算,导致 O(n²) 性能问题;不要直接调用 node.process(),应使用 tree.force_update() 或 tree.update_nodes();不要修改 sv_get(deepcopy=False) 返回的数据,否则会污染上游缓存与下游节点;程序化修改属性后必须调用 tree.force_update();更新前需确保 tree.sv_process = True;树类型必须为 'SverchCustomTreeType';插槽数据需用嵌套列表,如 sv_set([[(0,0,0), (1,0,0)]])。
适用场景:批量参数研究、外部脚本驱动 Sverchok 节点树、读取节点输出数据。具体版本兼容与更多 API 细节以官方文档与源码为准。