3

As I said in Title how template_search and template_search_preview works?

Edit:

I want to use template_search to give search functionality. Currently I'm using template_icon_view with enum. It gives me nice popup where i can browse asset but with large enums it's not good UX. enter image description here So I want to implement Search functionality. template_ID_preview can be used with only, well IDs not custom PropertyGroup

prop_search does work based on this example but it does not give thumbnail previews

I have this test code which gives me this result. I can't select from drop-down. And I get this error in console.

template_search_setup: pointer property not found: my_setting

enter image description here.

import bpy

class SceneSettingItem(bpy.types.PropertyGroup): name: bpy.props.StringProperty(name="Test Property", default="Unknown") value: bpy.props.IntProperty(name="Test Property", default=22)

bpy.utils.register_class(SceneSettingItem)

bpy.types.Scene.my_settings = bpy.props.CollectionProperty(type=SceneSettingItem) bpy.types.Scene.my_setting = bpy.props.PointerProperty(type=SceneSettingItem)

my_item = bpy.context.scene.my_settings.add() my_item.name = "Spam" my_item.value = 1000

my_item = bpy.context.scene.my_settings.add() my_item.name = "Eggs" my_item.value = 30

my_item = bpy.context.scene.my_settings.add() my_item.name = "Foo" my_item.value = 1000

class HelloWorldPanel(bpy.types.Panel): """Creates a Panel in the Object properties window""" bl_label = "Hello World Panel" bl_idname = "OBJECT_PT_hello" bl_space_type = 'VIEW_3D' bl_region_type = 'UI'

def draw(self, context):
    layout = self.layout

    obj = context.object

    row = layout.row()
    row.template_search(context.scene,"my_setting",context.scene,"my_settings")

    row = layout.row()
    row.prop(context.scene,"my_setting")

def register(): bpy.utils.register_class(HelloWorldPanel)

def unregister(): bpy.utils.unregister_class(HelloWorldPanel)

if name == "main": register()

Reigen
  • 895
  • 5
  • 15

0 Answers0