How to add an eyedropper functionality to prop_search
in my addon?
col.prop_search(scene, "string_property", context.scene, "objects")
This code will create prop_search
just like on the animation below, but without an eyedropper.
I spoke to Campbell Barton (the developer who got eyedropper functionality implemented) about this, he said that this kind of functionality is not available in Python API at the moment.
UPDATE:
Blender 2.79 now allows to create add-on properties which reference datablocks.
custom_property: PointerProperty(type=bpy.types.Object)
Using this property with a prop_search()
we'll get search box with an eyedropper.
UPDATE 2:
Usage of prop_search()
is not necessary, in this case prop()
will do just fine.
Noted by J. Bakker.
prop_search
, just a regular prop
, you will get a Eyedropper
$\endgroup$
Commented
Feb 19, 2018 at 19:48
A working example based on answers given.
Given the struggles of How to draw Object selection with eyedropper layout using Python script here is an edit to the script from that question
Puts a panel in the "scene" tab of the properties area.
import bpy
from bpy.props import PointerProperty
class TEST_PT_layout_panel(bpy.types.Panel):
bl_label = "Prop Panels"
bl_category = "Test Panel"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
scene = context.scene
layout = self.layout
col = layout.column()
col.prop_search(scene, "prop", context.scene, "objects")
#or
col.prop(scene, "prop")
def register():
bpy.types.Scene.prop = PointerProperty(type=bpy.types.Object)
bpy.utils.register_class(TEST_PT_layout_panel)
def unregister():
bpy.utils.unregister_class(TEST_PT_layout_panel)
if __name__ == "__main__":
register()
See https://blender.stackexchange.com/a/101303/15543 re creating a poll method for the pointer to filter, for example, for objects of type armature in the scene.
PointerProperty(type=bpy.types.Object)
, but it seems that pointer property points only to classes, and cannot store an ID block. $\endgroup$