Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created November 24, 2016 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/8bc7209b8cc7f011949d86bb00b11c3f to your computer and use it in GitHub Desktop.
Save zeffii/8bc7209b8cc7f011949d86bb00b11c3f to your computer and use it in GitHub Desktop.
prop_search on bpy.props.CollectionProperty
# ##### 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 bpy.props import EnumProperty
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import (updateNode, enum_item as e)
class SvGetDataObjectNode(bpy.types.Node, SverchCustomTreeNode):
''' Get Object Props '''
bl_idname = 'SvGetDataObjectNode'
bl_label = 'Object ID Get'
bl_icon = 'OUTLINER_OB_EMPTY'
M = [
'actions','brushes','filepath','grease_pencil','groups',
'images','libraries','linestyles','masks','materials',
'movieclips','node_groups','particles','scenes','screens','shape_keys',
'sounds','speakers','texts','textures','worlds','objects'
]
T = [
'MESH','CURVE','SURFACE','META','FONT','ARMATURE','LATTICE',
'EMPTY','CAMERA','LAMP','SPEAKER'
]
def pre_updateNode(self, context):
# empty collection first
self.collection_name.clear()
# now fill it up again
if self.Modes == 'objects':
for o in bpy.data.objects:
if o.type == self.Types: # o.type in {'FONT', 'META', 'CURVE', 'SURFACE', 'MESH'}
self.collection_name.add().name = o.name
updateNode(self, context)
Modes = EnumProperty(name="getmodes", default="objects", items=e(M), update=pre_updateNode)
Types = EnumProperty(name="getmodes", default="MESH", items=e(T), update=pre_updateNode)
obj_name = bpy.props.StringProperty(update=updateNode)
collection_name = bpy.props.CollectionProperty(type=bpy.types.PropertyGroup)
def draw_buttons(self, context, layout):
row = layout.row(align=True)
layout.prop(self, "Modes", "mode")
if self.Modes == 'objects':
layout.prop(self, "Types", "type")
layout.prop_search(self, 'obj_name', self, 'collection_name', icon='OBJECT_DATA')
def sv_init(self, context):
self.outputs.new('StringsSocket', "Objects")
def process(self):
sob = self.outputs['Objects']
if not sob.is_linked:
return
L = getattr(bpy.data,self.Modes)
if self.obj_name:
sob.sv_set([bpy.data.objects[self.obj_name]])
elif self.Modes != 'objects':
sob.sv_set(L[:])
else:
sob.sv_set([i for i in L if i.type == self.Types])
def register():
bpy.utils.register_class(SvGetDataObjectNode)
def unregister():
bpy.utils.unregister_class(SvGetDataObjectNode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment