Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created January 18, 2018 14:39
Show Gist options
  • Save zeffii/c981121becc6e3001b7860a3a45b6ffc to your computer and use it in GitHub Desktop.
Save zeffii/c981121becc6e3001b7860a3a45b6ffc to your computer and use it in GitHub Desktop.
Universal Connector
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
import bpy
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode
# this function will be located in the sv_obj_helper.py when it is merged
def enum_from_list_idx(*item_list):
results = []
for item in item_list:
idx, item_name = item.split(':')
results.append((item_name, item_name, "", int(idx)))
return results
sockets = [
"1:StringsSocket", "2:VerticesSocket", # "3:SvQuaternionSocket",
"4:SvColorSocket", "5:MatrixSocket",
# "6:SvDummySocket",
"7:ObjectSocket",
"9:SvObjectSocket"
# "8:SvTextSocket",
]
socket_types = enum_from_list_idx(*sockets)
class SvUniversalConnector(bpy.types.Node, SverchCustomTreeNode):
''' Universal connector '''
bl_idname = 'SvUniversalConnector'
bl_label = 'Universal Connector'
bl_icon = 'PLUGIN'
def wrapped_process(self, context):
self.outputs[0].replace_socket(self.selected_socket)
self.process_node(context)
selected_socket = bpy.props.EnumProperty(
name="Select Socket",
items=socket_types, description="offers....", update=wrapped_process
)
def sv_init(self, context):
self.inputs.new('SvDummySocket', 'input')
self.outputs.new('SvDummySocket', 'output')
def draw_buttons(self, context, layout):
layout.prop(self, "selected_socket", text='', icon='PLUGIN')
def process(self):
in_sock = self.inputs[0]
out_sock = self.outputs[0]
if in_sock.is_linked:
if (in_sock.bl_idname != in_sock.other.bl_idname):
in_sock.replace_socket(in_sock.other.bl_idname)
out_sock.sv_set(in_sock.sv_get())
def register():
bpy.utils.register_class(SvUniversalConnector)
def unregister():
bpy.utils.unregister_class(SvUniversalConnector)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment