I just made everything double:
import os
import bpy
def enum_previews_from_directory_items(self, context):
"""EnumProperty callback"""
enum_items = []
if context is None:
return enum_items
wm = context.window_manager
directory = wm.my_previews_dir
# Get the preview collection (defined in register func).
pcoll = preview_collections["main"]
if directory == pcoll.my_previews_dir:
return pcoll.my_previews
print("Scanning directory: %s" % directory)
def_dir = os.path.dirname(bpy.data.filepath) + directory[1:]
if directory and os.path.exists(def_dir):
# Scan the directory for png files
image_paths = []
for fn in os.listdir(def_dir):
if fn.lower().endswith(".png"):
image_paths.append(fn)
for i, name in enumerate(image_paths):
# generates a thumbnail preview for a file.
filepath = os.path.join(def_dir, name)
thumb = pcoll.load(filepath, filepath, 'IMAGE')
enum_items.append((name, name, "", thumb.icon_id, i))
pcoll.my_previews = enum_items
pcoll.my_previews_dir = directory
return pcoll.my_previews
def enum_previews_from_directory_items2(self, context):
"""EnumProperty callback"""
enum_items = []
if context is None:
return enum_items
wm = context.window_manager
directory = wm.my_previews_dir2
# Get the preview collection (defined in register func).
pcoll = preview_collections["main2"]
if directory == pcoll.my_previews_dir2:
return pcoll.my_previews2
print("Scanning directory: %s" % directory)
def_dir = os.path.dirname(bpy.data.filepath) + directory[1:]
if directory and os.path.exists(def_dir):
# Scan the directory for png files
image_paths = []
for fn in os.listdir(def_dir):
if fn.lower().endswith(".png"):
image_paths.append(fn)
for i, name in enumerate(image_paths):
# generates a thumbnail preview for a file.
filepath = os.path.join(def_dir, name)
thumb = pcoll.load(filepath, filepath, 'IMAGE')
enum_items.append((name, name, "", thumb.icon_id, i))
pcoll.my_previews2 = enum_items
pcoll.my_previews_dir2 = directory
return pcoll.my_previews2
class PreviewsExamplePanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Previews Example Panel"
bl_idname = "OBJECT_PT_previews"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
def draw(self, context):
layout = self.layout
wm = context.window_manager
row = layout.row()
row.prop(wm, "my_previews_dir")
row = layout.row()
row.template_icon_view(wm, "my_previews")
row = layout.row()
row.prop(wm, "my_previews")
row = layout.row()
row.prop(wm, "my_previews_dir2")
row = layout.row()
row.template_icon_view(wm, "my_previews2")
row = layout.row()
row.prop(wm, "my_previews2")
# We can store multiple preview collections here,
# however in this example we only store "main"
preview_collections = {}
def register():
from bpy.types import WindowManager
from bpy.props import (
StringProperty,
EnumProperty,
)
WindowManager.my_previews_dir = StringProperty(
name="Folder Path",
subtype='DIR_PATH',
default=""
)
WindowManager.my_previews = EnumProperty(
items=enum_previews_from_directory_items,
)
WindowManager.my_previews_dir2 = StringProperty(
name="Folder Path",
subtype='DIR_PATH',
default=""
)
WindowManager.my_previews2 = EnumProperty(
items=enum_previews_from_directory_items2,
)
# Note that preview collections returned by bpy.utils.previews
# are regular Python objects - you can use them to store custom data.
#
# This is especially useful here, since:
# - It avoids us regenerating the whole enum over and over.
# - It can store enum_items' strings
# (remember you have to keep those strings somewhere in py,
# else they get freed and Blender references invalid memory!).
import bpy.utils.previews
pcoll = bpy.utils.previews.new()
pcoll.my_previews_dir = ""
pcoll.my_previews = ()
pcoll2 = bpy.utils.previews.new()
pcoll2.my_previews_dir2 = ""
pcoll2.my_previews2 = ()
preview_collections["main"] = pcoll
preview_collections["main2"] = pcoll2
bpy.utils.register_class(PreviewsExamplePanel)
def unregister():
from bpy.types import WindowManager
del WindowManager.my_previews
for pcoll in preview_collections.values():
bpy.utils.previews.remove(pcoll)
preview_collections.clear()
bpy.utils.unregister_class(PreviewsExamplePanel)
if __name__ == "__main__":
register()
I am sure It can be done more professionally, but it's good starting point.
If You want more than two You should reed about collections