Skip to content

Instantly share code, notes, and snippets.

Created February 11, 2018 10:53
Show Gist options
  • Save zeffii/6c45a37301a96ee3033d195a9d78f4f7 to your computer and use it in GitHub Desktop.
Save zeffii/6c45a37301a96ee3033d195a9d78f4f7 to your computer and use it in GitHub Desktop.
demo layers filter properties
# This file is part of project Sverchok. It's copyrighted by the contributors
# recorded in the version control history of the file, available from
# its original location
# SPDX-License-Identifier: GPL3
# License-Filename: LICENSE
import bpy
# import mathutils
# from mathutils import Vector
# from bpy.props import FloatProperty, BoolProperty
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode
def pre_updateNode(self, context):
''' must rebuild for each update'''
for node in self.id_data.nodes:
if node.bl_idname == 'ViewerNode2':
self.collection_name.add().name =
# updateNode(self, context)
class SvVDMK2LayerOperatorCallback(bpy.types.Operator):
"""delegate changes to node"""
bl_idname = "nodes.sv_vdmk2_layer_cb"
bl_label = "Sv Ops Layer vd"
fn_name = bpy.props.StringProperty()
nt_name = bpy.props.StringProperty()
node_name = bpy.props.StringProperty()
def execute(self, context):
n = context.node
getattr(n, self.fn_name)()
return {"FINISHED"}
class SvVDMK2LayerGroup(bpy.types.PropertyGroup):
collection_name = bpy.props.CollectionProperty(type=bpy.types.PropertyGroup)
vd_node_name = bpy.props.StringProperty(update=pre_updateNode)
# vd_enum_nodes = bpy.props.EnumProperty()
vd_node_viewstate = bpy.props.BoolProperty()
class SvVDMK2LayerNode(bpy.types.Node, SverchCustomTreeNode):
''' VDMK layer teste '''
bl_idname = 'SvVDMK2LayerNode'
bl_label = 'VDMK Layers'
bl_icon = 'CAMERA_STEREO'
vd_layers = bpy.props.CollectionProperty(name="Viewer Draw Layers", type=SvVDMK2LayerGroup)
def sv_init(self, context):
self.width = 300
def draw_buttons(self, context, layout):
cb = SvVDMK2LayerOperatorCallback.bl_idname
tree = self.id_data
for viewer in self.vd_layers:
row = layout.row(align=True)
part1 = row.split(0.6)
part1.prop_search(viewer, "vd_node_name", viewer, 'collection_name', icon='OBJECT_DATA', text='')
viewer_node = tree.nodes.get(viewer.vd_node_name)
if viewer_node:
part2 = part1.split(align=True)
part2.prop(viewer_node, "activate", toggle=True, icon='VISIBLE_IPO_ON', text='')
part2.prop(viewer_node, "shading", toggle=True, icon='LAMP_SPOT', text='')
part2.prop(viewer_node, "vertex_colors", text='')
part2.prop(viewer_node, "edge_colors", text='')
part2.prop(viewer_node, "face_colors", text='')
layout.row().operator(cb, text='', icon='PLUS').fn_name = "ops_add_new_layer"
def process(self):
def ops_add_new_layer(self):
m = self.vd_layers.add()
m.vd_node_name = ''
def ops_activate_helper(self, mode):
for viewer in self.vd_layers:
viewer_node = tree.nodes.get(viewer.vd_node_name)
if viewer_node:
viewer_node.activate = mode
def ops_hide_layers(self):
classes = SvVDMK2LayerOperatorCallback, SvVDMK2LayerGroup, SvVDMK2LayerNode
def register():
_ = [bpy.utils.register_class(cls) for cls in classes]
def unregister():
_ = [bpy.utils.register_class(cls) for cls in reverse(classes)]
if __name__ == '__main__':
except Exception as err:
nodes =['NodeTree'].nodes
newnode ='SvVDMK2LayerNode')
# layer_1 = newnode.vd_layers.add()
# layer_1.vd_node_name = "Viewer Draw"
# layer_1.vd_node_viewstate = nodes[layer_1.vd_node_name].activate
# layer_2 = newnode.vd_layers.add()
# layer_2.vd_node_name = "Viewer Draw.001"
# layer_2.vd_node_viewstate = nodes[layer_2.vd_node_name].activate
# layer_3 = newnode.vd_layers.add()
# layer_3.vd_node_name = "Viewer Draw.002"
# layer_3.vd_node_viewstate = nodes[layer_3.vd_node_name].activate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment