EnumProperty with an item displaying as empty

I have made 4 enums that get filled from a dict that gets created from a folder structure when blender launches (I have reduced the script for readability). However when I change the enums in this order:

Project: 3,
Location: 3-2,
Project: 1

The Location enum contains what it is supposed to but is blank and gives the error:

WARN (bpy.rna): K:\BlenderGit\blender\source\blender\python\intern\bpy_rna.c:1457 pyrna_enum_to_py: current value ‘1’ matches no enum in ‘Test_Variables’, ‘’, ‘location_l3_enum’

I don’t understand why it is behaving this way and i’ve been trying to figure it out for 3 days now.

I understand this is probably a really sub-optimal way of achieving what I need but I am still a novice.

bl_info = {
    "name": "test_enum",
    "author": "test",
    "version": (1, 0),
    "blender": (2, 80, 0),
    "description": "",
    "category": "3D View"}

import bpy
import os
from functools import reduce
from bpy.props import EnumProperty

def project_items(self, context):
    items = bpy.context.scene.test_vars.project_l2
    return items

def location_items(self, context):
    items = bpy.context.scene.test_vars.location_l3
    return items

def sub_location_items(self, context):
    items = bpy.context.scene.test_vars.sub_location_l4
    return items

def type_items(self, context):
    items = bpy.context.scene.test_vars.type_l5
    return items

def project_update(self, context):
    self_vars = bpy.context.scene.test_vars
    root_l1 = next(iter(self_vars.folder_structure))

    location_list = []

    try: # check if key exists
        reduce(dict.__getitem__, [root_l1, self_vars.project_l2_enum], self_vars.folder_structure)

    except KeyError: # if key doesn't exist add blank
        location_list.append(("--", "--", "None"))

    else: # if key exist

        if len(self_vars.folder_structure[root_l1][self_vars.project_l2_enum]) < 1: # if folder has no sub folders add blank
            location_list.append(("--", "--", "None"))

        else: # if folder has sub folders append folders
            for folder in self_vars.folder_structure[root_l1][self_vars.project_l2_enum]:
                location_list.append((folder, folder, "Location folder"))

    bpy.context.scene.test_vars.location_l3[:] = list(location_list)

    location_update(self, context)

def location_update(self, context):
    self_vars = bpy.context.scene.test_vars
    root_l1 = next(iter(self_vars.folder_structure))

    sub_location_list = []

    # sub-location - L4
    try:
        reduce(dict.__getitem__, [root_l1, self_vars.project_l2_enum, self_vars.location_l3_enum], self_vars.folder_structure)
    except KeyError:
        sub_location_list.append(("--", "--", "None"))
    else:
        if len(self_vars.folder_structure[root_l1][self_vars.project_l2_enum][self_vars.location_l3_enum]) < 1:
            sub_location_list.append(("--", "--", "None"))
        else:
            for folder in self_vars.folder_structure[root_l1][self_vars.project_l2_enum][self_vars.location_l3_enum]:
                sub_location_list.append((folder, folder, "Sub-Location folder"))

    bpy.context.scene.test_vars.sub_location_l4[:] = list(sub_location_list)

    sub_location_update(self, context)

def sub_location_update(self, context):
    self_vars = bpy.context.scene.test_vars
    root_l1 = next(iter(self_vars.folder_structure))

    type_list = []

    # type - L5
    try:
        reduce(dict.__getitem__, [root_l1, self_vars.project_l2_enum, self_vars.location_l3_enum, self_vars.sub_location_l4_enum], self_vars.folder_structure)
    except KeyError:
        type_list.append(("--", "--", "None"))
    else:
        if len(self_vars.folder_structure[root_l1][self_vars.project_l2_enum][self_vars.location_l3_enum][self_vars.sub_location_l4_enum]) < 1:
            type_list.append(("--", "--", "None"))
        else:
            for folder in self_vars.folder_structure[root_l1][self_vars.project_l2_enum][self_vars.location_l3_enum][self_vars.sub_location_l4_enum]:
                type_list.append((folder, folder, "Type folder"))

    bpy.context.scene.test_vars.type_l5[:] = list(type_list)


class Test_Variables(bpy.types.PropertyGroup):
    # file structure
    folder_structure = {'Root': {'1': {'1-1': {'1-1-1': {'1-1-1-1': None, '1-1-1-2': None, '1-1-1-3': None}}}, '2': {}, '3': {'3-1': {}, '3-2': {'3-2-1': {'3-2-1-1': None, '3-2-1-2': None}}}}}

    # file paths
    project_l2 = [("1", "1", "1"), ("2", "2", "2"), ("3", "3", "3") ]
    location_l3 = [("1-1", "1-1", "1-1")]
    sub_location_l4 = [("1-1-1", "1-1-1", "1-1-1")]
    type_l5 = [("1-1-1-1", "1-1-1-1", "1-1-1-1")]

    # enums
    project_l2_enum : bpy.props.EnumProperty(
        items = project_items,
        name = "Project",
        default = None,
        update = project_update,
    )

    location_l3_enum : bpy.props.EnumProperty(
        items = location_items,
        name = "Location",
        default = None,
        update = location_update,
    )

    sub_location_l4_enum : bpy.props.EnumProperty(
        items = sub_location_items,
        name = "subLocation",
        default = None,
        update = sub_location_update,
    )

    type_l5_enum : bpy.props.EnumProperty(
        items = type_items,
        name = "Type",
        default = None,
    )


class Test_Panel(bpy.types.Panel):
    bl_label = "test_panel"
    bl_idname = "PANEL_PT_test_panel"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'

    def draw(self, context):

        layout = self.layout
        scene = context.scene
        self_vars = scene.test_vars

        box = layout.box()
        col = box.column(align = True)
        row = col.row(align = True)

        row.prop(self_vars, "project_l2_enum", text = "Project: ", icon = "FILE_FOLDER")
        col = box.column(align = True)
        row = col.row(align = True)
        row.prop(self_vars, "location_l3_enum", text = "Location: ", icon = "MATPLANE")
        col = box.column(align = True)
        row = col.row(align = True)
        row.prop(self_vars, "sub_location_l4_enum", text = "SubLocation: ", icon = "MATPLANE")
        col = box.column(align = True)
        row = col.row(align = True)
        row.prop(self_vars, "type_l5_enum", text = "Type: ", icon = "MATPLANE")


classes = (
    Test_Variables,
    Test_Panel,
)

def register():
    for cls in classes:
        bpy.utils.register_class(cls)
    bpy.types.Scene.test_vars = bpy.props.PointerProperty(type = Test_Variables)

def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)
    del bpy.types.Scene.test_vars

if __name__ == "__main__":
    register()

hi, i just ran in the same issue, no luck in fixing it so far ?

def project_update(self, context):
    self_vars = bpy.context.scene.d_save_vars

    # store root folder name from folder structure
    root_l1 = next(iter(self_vars.d_folder_structure))

    # initialize temporary list
    location_list = []

    try:
        # check if key exists
        reduce(dict.__getitem__, [root_l1, self_vars.d_project_l2_enum], self_vars.d_folder_structure)

    except KeyError:
        # if key doesn't exist add blank to enum
        location_list.append(("--", "--", "None"))
    else:
        # if key exists but there are no subfolders add blank to enum
        if len(self_vars.d_folder_structure[root_l1][self_vars.d_project_l2_enum]) < 1:
            location_list.append(("--", "--", "None"))
        else:
            # if key exists and has subfolders add the folder to the list
            for folder in self_vars.d_folder_structure[root_l1][self_vars.d_project_l2_enum]:
                location_list.append((folder, folder, "Location folder"))

    # clear list
    self_vars.d_location_l3.clear()

    # fill list from processed list
    for folder in location_list:
        self_vars.d_location_l3.append(folder)

    # set enum to index 0
    self_vars.d_location_l3_enum = str(location_list[0][0])

I got it to work by clearing and refilling

1 Like

thanks a lot ! :slight_smile: cheers !