7
$\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$
  • $\begingroup$ I think the property should be a pointer and the eyedropper will appear $\endgroup$ – Chebhou May 6 '15 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$ – Mikhail Rachinskiy May 7 '15 at 6:48
  • $\begingroup$ did you find something yet ? $\endgroup$ – Chebhou May 16 '15 at 18:51
7
$\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$
  • $\begingroup$ Did you submit a feature request in the Blender bug tracker? $\endgroup$ – vvoovv May 5 '16 at 22:56
  • $\begingroup$ I added a feature request to the Blender tracker: developer.blender.org/T48357 $\endgroup$ – vvoovv May 5 '16 at 23:34
  • $\begingroup$ The same feature request at the new community website for Blender development ideas: rightclickselect.com/p/scripting/zkbbbc $\endgroup$ – vvoovv May 6 '16 at 15:05
  • $\begingroup$ @brockmann, example code $\endgroup$ – Mikhail Rachinskiy Jun 4 '17 at 5:15
  • 2
    $\begingroup$ Even without a prop_search, just a regular prop, you will get a Eyedropper $\endgroup$ – J. Bakker Feb 19 '18 at 19:48
0
$\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()
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.