I want to list some blend files from a folder in the UI. Reading the folder content already works. The output lands in a list. Now I need to display the content of this list in a template_list box. I am totally lost with this template_list.
My problem is basically:
mylist = []
...
row.template_list(what has to stand here to display the content of my list?)
So how do I get the list content into my template_list?
The as much as possible reduced script is at the moment in this state:
import bpy
import os
# -----------------------------------------------------------------------------------------------------
# the panel is in the properties sidebar.
# -----------------------------------------------------------------------------------------------------
mylist = []
class VIEW3D_read_dir(bpy.types.Operator):
"""Blubb"""
bl_idname = "view3d.read_dir"
bl_label = "Read Dir"
def execute(self, context):
mylist = [] # empty the list
start_path = 'C:/Users/x/Documents' # current directory
for path,dirs,files in os.walk(start_path):
for filename in files:
if filename.endswith(".blend"):
mylist.append(os.path.join(filename)) # fill the list
print (mylist) #debugging
return {'FINISHED'}
class MyPanel(bpy.types.Panel):
bl_label = "Testpanel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
def draw(self, context):
layout = self.layout
layout.operator("view3d.read_dir", text="read directory") # Button to read the directory
scene = context.scene
row = layout.row()
row.template_list("UI_UL_list", "keying_sets", scene, "keying_sets", scene.keying_sets, "active_index", rows=1) #Grabbed from Keying Sets to have a template list to play with
# ------------------------------ register unregister --------------------------------------------------------
def register():
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()
TEXT_EDITOR
) combined with anImportHelper
to get multiple blend files at once. This is what you want right? $\endgroup$ – p2or Oct 22 '16 at 12:31