I'm defining a directory tree using a template_list...
(Looks similar to a Windows7 directory tree)  Everything works properly, showing the drives and initial expanded folders as expected...

But when I click one of the arrows (BoolProperty), nothing happens to the list...

Currently I'm using a simple code which clears and rebuilds the collection when an arrow is clicked,

The process calls an update function supplied to the BoolProperty on registration. When the function is invoked, it clears the collection property and does a recursive scan of the expanded folders using os.listdir(). If os.path.isdir() returns valid, a folder (PropertyGroup) is added and set. (If the directory is listed in the expanded directories, it's marked expanded and recursed)

def recurse(directory,level=0):
    global folders
    for entry in os.listdir(directory):
        fullpath=( '%s%s' if directory[-1]=='/' else '%s/%s' )%(directory,entry)
        if os.path.isdir(fullpath):
            if fullpath in expanded_directories:

def expand_toggle(folder,context):
    global toggle,expanded_directories
    # NOTE: folder.expand is set before getting here
    if toggle: # this should ONLY be True when folder.expand is clicked (not set)
        toggle=False # don't update when setting `folder.expand`

        if folder.expand: expanded_directories.append( folder.path )
        elif folder.path in expanded_directories: expanded_directories.remove( folder.path )

        # NOTE: the initial invoke of the dialog class does the same thing as here (no recursion).

        folders.clear()  # why doesn't this clear the UI?

        for drive in drives:
            folder.name=drive.split('/')[-1] or '/'
            folder.level=0 # drives are the roots
            if drive in expanded_directories:
                folder.expand=True # this would call this function (recursion depth error)


If the BoolProperty is toggled True, the current path (StringProperty) is appended to the expanded directories. If toggled False and the path is appended, it's removed.

But the links to the folders (PropertyGroup items) are lost when .add() is called to update the CollectionProperty...

Meaning the added folder is not part of the group .add() was called from.
Instead it gets added to context.scene directly, which is useless...

Nothing changes in the UI.

How can I achieve the expected behaviour?

EDIT: if I re-open the dialog (without clearing the expanded folders (python list)), you can then see the changes.

  • 1
    $\begingroup$ I don't think people will be able to fully help you without seeing at least some of your code. Also, as an aside, what is the reason for creating your own file browser instead of using blender's? $\endgroup$ Nov 28, 2016 at 15:30
  • $\begingroup$ Yea, I don't think I'll be able to do much there, I can't simply copy/paste... maybe I should describe the process a bit better... it shouldn't be hard to help me without my code. and the reason for my own is because blender doesn't have a friendly folder-only selection interface.. file specification would simply confuse the user, since my export script exports the model, textures, animations, and even shaders to subdirectories in the specified directory. $\endgroup$
    – Tcll
    Nov 28, 2016 at 20:38
  • $\begingroup$ Yay, I figured out how to copy/paste a text document on this stupid thing. ^_^ $\endgroup$
    – Tcll
    Nov 29, 2016 at 13:27
  • 3
    $\begingroup$ Blender does have a folder-only interface if you use the subtype='DIR_PATH' option when creating a StringProperty. Here: blender.stackexchange.com/questions/26898/… or use one of the 'Operator File Export' templates that comes with blender. $\endgroup$ Nov 29, 2016 at 13:32
  • $\begingroup$ Thanks, I did initially try the 'DIR_PATH' option on the "Minecraft Directory" string property, but clicking the button did nothing... your reference might help with that, but I still need to update a template list (the left one shown above) when selecting a character, so may as well just answer this question to answer that... lol $\endgroup$
    – Tcll
    Nov 29, 2016 at 13:39


You must log in to answer this question.

Browse other questions tagged .