Take the 2-minute tour ×
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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_69_release/bpy.props.html#bpy.props.EnumProperty

share|improve this answer
    
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? –  lucblender Feb 28 at 9:45
    
Every time its accessed - thats why you pass a function that generates a list, rather then a list. –  ideasman42 Feb 28 at 9:48
    
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 –  lucblender Feb 28 at 9:52
    
@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 –  ideasman42 Feb 28 at 10:41
    
Ohh I understand :) and now it's working Big thank's –  lucblender Feb 28 at 10:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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