0
$\begingroup$

I need an enum prop to be refreshed from a txt file when I click the drop down in a panel. I am using this as reference: https://blender.stackexchange.com/a/80968/51645

I have this so far:

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

import bpy
import os, errno
import pathlib
import re


def Item_Prefix(self, context):
    prefix_list = []
    count = 0
    path = "C:\\Users\\Testing_1.txt"

    with open(path, 'r') as f:

        prefix = ([line.strip() for line in f])

    for entry in prefix:
        count += 1
        prefix_list.append((entry,entry,entry, count))

    print(prefix_list)

    return prefix_list


class Prefix_Variables(bpy.types.PropertyGroup):

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


class Testing_Panel(bpy.types.Panel):
    bl_idname = "panel.testing_panel"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_category = "Tools"
    bl_label = "Testing_Panel"

    def draw(self, context):

        layout = self.layout
        box = layout.box()

        row.prop(bpy.context.scene.prefix_vars, 'save_prefix', text = "")


def register():
    bpy.utils.register_class(Testing_Panel)
    bpy.utils.register_class(Prefix_Variables)
    bpy.types.Scene.prefix_vars = bpy.props.PointerProperty(type = Prefix_Variables)


def unregister():
    bpy.utils.unregister_class(Testing_Panel)
    bpy.utils.unregister_class(Prefix_Variables)
    del bpy.types.Scene.prefix_vars

It is working, but it is just looping constantly, I only want it to do it when I click the panel prop.

$\endgroup$
5
  • 1
    $\begingroup$ AFAIK what you are seeing is expected behaviour. The enum is in a panel draw method, every time the draw method updates the the enum property checks its items. Suggest leaving as is, but reading file list into a global, and only updating the global list when the file is touched. $\endgroup$
    – batFINGER
    Commented Apr 22, 2018 at 15:59
  • $\begingroup$ So is there no way to only check the file when I click the prop? I don't want to be needlessly checking a file for changes considering the file will only be updated once a month. $\endgroup$
    – Way2Close
    Commented Apr 22, 2018 at 16:12
  • 1
    $\begingroup$ Why even bother with a dynamic enum? Load the list when you register the property? $\endgroup$
    – batFINGER
    Commented Apr 22, 2018 at 16:14
  • $\begingroup$ Yeah I think you are right, I was trying to get unnecessarily fancy, Thank you so much, sorry for wasting your time haha $\endgroup$
    – Way2Close
    Commented Apr 22, 2018 at 16:18
  • $\begingroup$ Lol. Have "wasted" far far too much time going for unnecessarly fancy too. $\endgroup$
    – batFINGER
    Commented Apr 22, 2018 at 16:22

0

You must log in to answer this question.

Browse other questions tagged .