How to set a default value for an EnumProperty that is populated by an items function?

Hi

I am trying to make a default value for an EnumProperty whose items are generated by an items function like below. Defining a default value in such situation makes the ui element of that property dissappear, clearly Blender does not like it.

Normally the line below is created and populated as a regular enum prop. And it quite functional in my add-on.

category_id = EnumProperty(
        name="id",items=items_func, update=update_func)

This is the version that is not working naturally.

category_id = EnumProperty(
        name="id",default="Default",items=items_func, update=update_func)

It is clear that it is not easy to make something default when it does not exist, given that it needs to be populated first. So what would be the recommended way to go about such need?

thanks

The docs for EnumProperty say that the default is None:

default ( string or set ) – The default value for this enum (…). WARNING: It shall not be specified (or specified to its default None value) for dynamic enums (i.e. if a callback function is given as items parameter).

…but from what I tested here in 2.79 it’s the first item of the iterable that items_func() returns. So in the absence of being able to set a default, order the items so that the first item is what you expect as default.

2 Likes