Last active
May 21, 2023 18:21
-
-
Save p2or/e14a6470be25e87ed596 to your computer and use it in GitHub Desktop.
UI - PropSearch #Blender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for http://blender.stackexchange.com/questions/44886/search-enum-list | |
bl_info = { | |
"name": "Search Popup", | |
"version": (0, 0, 1), | |
"blender": (2, 75, 0), | |
"category": "Test" | |
} | |
import bpy | |
from bpy.props import (EnumProperty, | |
PointerProperty, | |
) | |
from bpy.types import (Operator, | |
AddonPreferences, | |
PropertyGroup, | |
) | |
# ------------------------------------------------------------------------ | |
# store properties in the active scene | |
# ------------------------------------------------------------------------ | |
def my_callback(scene, context): | |
mat_cids = ([o for o in bpy.data.materials['Material'].keys() ]) | |
return [(y.upper(), y, "", x) for x, y in enumerate(mat_cids)] | |
class MySettings(PropertyGroup): | |
objs = EnumProperty( | |
name="Objects", | |
description="", | |
items=my_callback | |
) | |
# ------------------------------------------------------------------------ | |
# operator | |
# ------------------------------------------------------------------------ | |
class MyOperator(Operator): | |
"""Tooltip""" | |
bl_idname = "object.search_popup" | |
bl_label = "Search Popup" | |
bl_property = "my_enum" | |
my_enum = MySettings.objs | |
def execute(self, context): | |
self.report({'INFO'}, "You've selected: %s" % self.my_enum) | |
return {'FINISHED'} | |
def invoke(self, context, event): | |
wm = context.window_manager | |
wm.invoke_search_popup(self) | |
return {'FINISHED'} | |
# ------------------------------------------------------------------------ | |
# register and unregister functions | |
# ------------------------------------------------------------------------ | |
def register(): | |
bpy.utils.register_module(__name__) | |
bpy.types.Scene.my_tool = PointerProperty(type=MySettings) | |
def unregister(): | |
bpy.utils.unregister_module(__name__) | |
del bpy.types.Scene.my_tool | |
if __name__ == "__main__": | |
register() | |
# test call | |
bpy.ops.object.search_popup('INVOKE_DEFAULT') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment