I have a dropdown box. And i want to do this when this item is selected, and that when another item is selected. So i need a way to retreive what is currently selected in the dropdown menu.

The dropdown menu is a EnumProperty. Like the dropdown box to change the rotation mode.

bpy.types.Scene.enumprop = bpy.props.EnumProperty(items = item_cb)

layout.prop(scene, 'enumprop', text='Files')

How do i retreive the value of the current selection from a dropdown menu by code?

  • $\begingroup$ Looks good. How your callback looks like? What exactly is wrong with this? From the API: update is called when this value is modified $\endgroup$ – p2or Oct 22 '16 at 17:19
  • $\begingroup$ @poor, The callback was exactly my problem. I had initially no idea how to do it. But i have meanwhile solved it. See answer below :) $\endgroup$ – Tiles Oct 22 '16 at 17:28
  • 1
    $\begingroup$ I'd avoid update, that's why I posted the API quote. $\endgroup$ – p2or Oct 22 '16 at 18:31
  • $\begingroup$ Yes, that's what i did in the end then :) $\endgroup$ – Tiles Oct 22 '16 at 18:34

The solution was to add a update to the prop. Then i can retreive changes from the dropdown box.

def myindex(self, context):
    print('changed to,', context.scene.MyEnum)

bpy.types.Scene.MyEnum = bpy.props.EnumProperty(items = item_cb, update = myindex)  

Another way goes directly across int(context.scene.MyEnum). Then i don't need the update.

|improve this answer|||||

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.