Load and update enum values I have an enum in my panel and I wonder how I can populate it from a file and then refresh it when needed instead of being static as shown below.

So if I have a text file populate.txt with the below format it should give the same result as the above one so that the values in the text file will be populated in my panel when it's loaded:

populate.txt:
1.5,A, 
2.4,B, 
-5.2,C, 


I also wonder how I can refresh the list after the panel is already drawn and the enum is drawn (read from the text file and update the list).

This is my current script:

import bpy
from bpy.types import Panel, PropertyGroup
from bpy.props import EnumProperty, PointerProperty
from bpy.types import Scene

bl_info = {
    "name": "prop",
    "description": "prop",
}


class PropVal(PropertyGroup):
    enumv = EnumProperty(
        name="my_enum_name:",
        description="my_enum_description",
        items=[ ("1.5", "A", ""),
                ("2.4", "B", ""),
                ("-5.2", "C", ""),
               ]
        )

class EnumPanel(Panel):
    bl_idname = "EnumPanel"
    bl_label = "Panel"
    bl_space_type = "VIEW_3D"   
    bl_region_type = "TOOLS"    
    bl_category = "Tools"

    def draw(self, context):
        layout = self.layout
        scene = context.scene
        enumval = scene.enumval
        layout.prop(enumval, "enumv")

def register():
    bpy.utils.register_module(__name__)
    bpy.types.Scene.enumval = PointerProperty(type=PropVal)

def unregister():
    bpy.utils.unregister_module(__name__)
    del bpy.types.Scene.enumval

if __name__ == "__main__":
    register()


And this is my result:
bpy.props.EnumProperty can be of static nature (as in your example) or dynamic.

bpy.props.EnumProperty(items, name="", description="", default=None, options={'ANIMATABLE'}, update=None, get=None, set=None)


A dynamic enum is one whose items are calculated when clicked on, for example.

def items_file(self, context):
    items = []
    # open file
    # construct a tuple
    # append to items
    return items


Now whenever you click the enum property in the Panel, the items will be fetched from the callback.

Note:


The default parameter must be None for dynamic enum
In the callback, the items must always be assigned to a local variable, populated and then returned (to avoid crash: and this is a documented bug)


https://docs.blender.org/api/current/bpy.props.html