10
$\begingroup$

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.

eyedropper

$\endgroup$
3
  • $\begingroup$ I think the property should be a pointer and the eyedropper will appear $\endgroup$
    – Chebhou
    Commented May 6, 2015 at 12:40
  • $\begingroup$ I already tried PointerProperty(type=bpy.types.Object), but it seems that pointer property points only to classes, and cannot store an ID block. $\endgroup$ Commented May 7, 2015 at 6:48
  • $\begingroup$ did you find something yet ? $\endgroup$
    – Chebhou
    Commented May 16, 2015 at 18:51

2 Answers 2

10
$\begingroup$

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.

$\endgroup$
10
  • $\begingroup$ Did you submit a feature request in the Blender bug tracker? $\endgroup$
    – vvoovv
    Commented May 5, 2016 at 22:56
  • $\begingroup$ I added a feature request to the Blender tracker: developer.blender.org/T48357 $\endgroup$
    – vvoovv
    Commented May 5, 2016 at 23:34
  • $\begingroup$ The same feature request at the new community website for Blender development ideas: rightclickselect.com/p/scripting/zkbbbc $\endgroup$
    – vvoovv
    Commented May 6, 2016 at 15:05
  • $\begingroup$ @brockmann, example code $\endgroup$ Commented Jun 4, 2017 at 5:15
  • 4
    $\begingroup$ Even without a prop_search, just a regular prop, you will get a Eyedropper $\endgroup$
    – J. Bakker
    Commented Feb 19, 2018 at 19:48
4
$\begingroup$

A working example based on answers given.

enter image description here

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.

$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .