I'm writting an addon with an UI. In my draw function in my UI class I've this

layout.prop(bpy.context.scene, 'activebone', text='active bone')

Wich create an enum in the UI.

And in my register class I've this:

bpy.types.Scene.activebone = bpy.props.EnumProperty(items=active_bone)

In my draw fonction I fill the active_bone list with the some data and but the enum don't refresh himself. I know that i can retype

bpy.types.Scene.activebone = bpy.props.EnumProperty(items=active_bone)

But the draw function is Read only so I can't. Is it possible to refresh my Enum item in the draw function or am I obliged to do it in an other class like a button?


In this case it sounds like you want to use a dynamic enum, rather then passing a list, pass items as a function (which returns a list), then you can change it dynamically.

See: http://www.blender.org/documentation/blender_python_api_2_73_release/bpy.props.html#bpy.props.EnumProperty

| improve this answer | |
  • $\begingroup$ That's not exacly what I want because in my case the enum data will change for every object. Or I haven't understand your answer. In your case the enum will fill himself only at the start of the script or every time the UI refresh? $\endgroup$ – lucblender Feb 28 '14 at 9:45
  • $\begingroup$ Every time its accessed - thats why you pass a function that generates a list, rather then a list. $\endgroup$ – ideasman42 Feb 28 '14 at 9:48
  • $\begingroup$ So now I've that: bpy.props.EnumProperty(items=listBone()) but it's in the register function it can't be in the draw function of the UI so it can be refreshed in the same time of the UI. So the only possibility I see is to refresh my enum with a button or a timer but I want it to be refreshed automaticaly with the UI. Sorry if I'm not clear :S $\endgroup$ – lucblender Feb 28 '14 at 9:52
  • $\begingroup$ @lucblender, this isnt how callbacks work, you need to pass the function without calling, so bpy.props.EnumProperty(items=listBone) where listBone is a function you have defined. See scripts/startup/bl_ui/__init__.py for an example of a callback - addon_filter_items $\endgroup$ – ideasman42 Feb 28 '14 at 10:41
  • $\begingroup$ Ohh I understand :) and now it's working Big thank's $\endgroup$ – lucblender Feb 28 '14 at 10:48

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.