From 91332b811b94589f72da8cea0a4c254353c7cf07 Mon Sep 17 00:00:00 2001 From: Dealga McArdle Date: Mon, 10 May 2021 12:01:45 +0200 Subject: [PATCH] add vd/mv onedir hotswap --- utils/macros/hotswap_macros.py | 20 ++++++++++++++++++++ utils/sv_default_macros.py | 17 +++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 utils/macros/hotswap_macros.py diff --git a/utils/macros/hotswap_macros.py b/utils/macros/hotswap_macros.py new file mode 100644 index 000000000..5c60635b3 --- /dev/null +++ b/utils/macros/hotswap_macros.py @@ -0,0 +1,20 @@ + +# hotswap_macros.py + +def swap_vd_mv(context, operator, term, nodes, links): + """ hotswap viewerdraw <---> meshview ///""" + active_node = context.active_node + if active_node and active_node.bl_idname == 'SvViewerDrawMk4': + loc = active_node.location[:] + tree = context.space_data.edit_tree + nodes, links = tree.nodes, tree.links + mv = tree.nodes.new('SvMeshViewer') + mv.location = loc + + a_inputs = active_node.inputs + link_matches = [[0, 0], [1, 1], [2, 2], [3, 4]] + for idx_a, idx_b in link_matches: + if a_inputs[idx_a].is_linked: + links.new(a_inputs[idx_a].links[0].from_socket, mv.inputs[idx_b]) + + nodes.remove(active_node) \ No newline at end of file diff --git a/utils/sv_default_macros.py b/utils/sv_default_macros.py index fc20d44c1..5e907a679 100644 --- a/utils/sv_default_macros.py +++ b/utils/sv_default_macros.py @@ -27,6 +27,7 @@ from sverchok.utils.macros.math_macros import math_macros from sverchok.utils.macros.join_macros import join_macros from sverchok.utils.macros.switch_macros import switch_macros from sverchok.utils.macros.gp_macros import gp_macro_one, gp_macro_two +from sverchok.utils.macros.hotswap_macros import swap_vd_mv # pylint: disable=c0301 @@ -108,6 +109,10 @@ macros = { 'display_name': "grease pencil setup", 'file': 'macro', 'ident': ['verbose_macro_handler', 'gp + 2']}, + "> hotswap vd mv": { + 'display_name': "hotswap vd->meshviewer", + 'file': 'macro', + 'ident': ['verbose_macro_handler', 'hotswap']}, "> url": { 'display_name': "download archive from url", 'file': 'macro', @@ -180,7 +185,7 @@ class DefaultMacros(): links.new(obj_in_node.outputs[0], vd_node.inputs[0]) links.new(obj_in_node.outputs[2], vd_node.inputs[2]) - links.new(obj_in_node.outputs[3], vd_node.inputs[3]) + links.new(obj_in_node.outputs[4], vd_node.inputs[3]) elif term == 'objs vd': obj_in_node = nodes.new('SvObjectsNodeMK3') @@ -190,7 +195,11 @@ class DefaultMacros(): links.new(obj_in_node.outputs[0], vd_node.inputs[0]) links.new(obj_in_node.outputs[2], vd_node.inputs[2]) - links.new(obj_in_node.outputs[3], vd_node.inputs[3]) + links.new(obj_in_node.outputs[4], vd_node.inputs[3]) + + elif 'hotswap' in term: + swap_vd_mv(context, operator, term, nodes, links) + return elif term == 'zen': full_url_term = 'https://gist.github.com/zeffii/d843b985b0db97af56dfa9c30cd54712' @@ -212,11 +221,11 @@ class DefaultMacros(): elif "math" in term: math_macros(context, operator, term, nodes, links) - return {'FINISHED'} + return elif "switch" in term: switch_macros(context, operator, term, nodes, links) - return {'FINISHED'} + return elif 'output numpy' in term: #stop processing to avoid one update per property -- GitLab