import os
import bpy
import bpy.utils.previews
from .. import util

asset_previews = bpy.utils.previews.new()

def load_previews(lib, start=0):
    global asset_previews
    enum_items = []

    lib_dir = presets_library = util.get_addon_prefs().presets_library.path

    for i,asset in enumerate(lib.presets):
        path = asset.path
        
        if path not in asset_previews:
            thumb_path = os.path.join(asset.path, 'asset_100.png')
            
            thumb = asset_previews.load(path, thumb_path, 'IMAGE', force_reload=True)
        else:
            thumb = asset_previews[path]
        enum_items.append((asset.path, asset.label, '', thumb.icon_id, start + i))
        
    start += len(enum_items)
    for sub_group in lib.sub_groups:
        enum_items.extend(load_previews(sub_group, start))

    return enum_items if enum_items else [('', '', '')]
import os
import bpy
import bpy.utils.previews
from .. import util

asset_previews = bpy.utils.previews.new()

def get_presets_for_lib(lib):
    items = list(lib.presets)
    for sub_group in lib.sub_groups:
        items.extend(get_presets_for_lib(sub_group))
    return items

def load_previews(lib):
    global asset_previews
    enum_items = []

    lib_dir = presets_library = util.get_addon_prefs().presets_library.path

    items = get_presets_for_lib(lib)
    items = sorted(items, key=lambda item: item.label)

    for i, asset in enumerate(items):
        path = asset.path
        
        if path not in asset_previews:
            thumb_path = os.path.join(asset.path, 'asset_100.png')
            
            thumb = asset_previews.load(path, thumb_path, 'IMAGE', force_reload=True)
        else:
            thumb = asset_previews[path]
        enum_items.append((asset.path, asset.label, '', thumb.icon_id, i))

    return enum_items if enum_items else [('', '', '')]
Fix order in icon preview.
Fix order in icon preview.

  import os
  import bpy
  import bpy.utils.previews
  from .. import util
  
  asset_previews = bpy.utils.previews.new()
  
+ def get_presets_for_lib(lib):
+     items = list(lib.presets)
+     for sub_group in lib.sub_groups:
+         items.extend(get_presets_for_lib(sub_group))
+     return items
+ 
- def load_previews(lib, start=0):
+ def load_previews(lib):
      global asset_previews
      enum_items = []
  
      lib_dir = presets_library = util.get_addon_prefs().presets_library.path
  
+     items = get_presets_for_lib(lib)
+     items = sorted(items, key=lambda item: item.label)
+ 
-     for i,asset in enumerate(lib.presets):
+     for i, asset in enumerate(items):
          path = asset.path
          
          if path not in asset_previews:
              thumb_path = os.path.join(asset.path, 'asset_100.png')
              
              thumb = asset_previews.load(path, thumb_path, 'IMAGE', force_reload=True)
          else:
              thumb = asset_previews[path]
-         enum_items.append((asset.path, asset.label, '', thumb.icon_id, start + i))
+         enum_items.append((asset.path, asset.label, '', thumb.icon_id, i))
-         
-     start += len(enum_items)
-     for sub_group in lib.sub_groups:
-         enum_items.extend(load_previews(sub_group, start))
  
      return enum_items if enum_items else [('', '', '')]
Fix order in icon preview.
## Code Before:
import os
import bpy
import bpy.utils.previews
from .. import util

asset_previews = bpy.utils.previews.new()

def load_previews(lib, start=0):
    global asset_previews
    enum_items = []

    lib_dir = presets_library = util.get_addon_prefs().presets_library.path

    for i,asset in enumerate(lib.presets):
        path = asset.path
        
        if path not in asset_previews:
            thumb_path = os.path.join(asset.path, 'asset_100.png')
            
            thumb = asset_previews.load(path, thumb_path, 'IMAGE', force_reload=True)
        else:
            thumb = asset_previews[path]
        enum_items.append((asset.path, asset.label, '', thumb.icon_id, start + i))
        
    start += len(enum_items)
    for sub_group in lib.sub_groups:
        enum_items.extend(load_previews(sub_group, start))

    return enum_items if enum_items else [('', '', '')]
## Instruction:
Fix order in icon preview.
## Code After:
import os
import bpy
import bpy.utils.previews
from .. import util

asset_previews = bpy.utils.previews.new()

def get_presets_for_lib(lib):
    items = list(lib.presets)
    for sub_group in lib.sub_groups:
        items.extend(get_presets_for_lib(sub_group))
    return items

def load_previews(lib):
    global asset_previews
    enum_items = []

    lib_dir = presets_library = util.get_addon_prefs().presets_library.path

    items = get_presets_for_lib(lib)
    items = sorted(items, key=lambda item: item.label)

    for i, asset in enumerate(items):
        path = asset.path
        
        if path not in asset_previews:
            thumb_path = os.path.join(asset.path, 'asset_100.png')
            
            thumb = asset_previews.load(path, thumb_path, 'IMAGE', force_reload=True)
        else:
            thumb = asset_previews[path]
        enum_items.append((asset.path, asset.label, '', thumb.icon_id, i))

    return enum_items if enum_items else [('', '', '')]