I'm trying to fill a template_icon_view with Blender's default brushes, here's the code:

import bpy
import bpy.utils.previews
from bpy.types import WindowManager, EnumProperty
from bpy.props import EnumProperty

def getBrushPreviews(self, context):
    import bpy
    previews = []
    index = 0
    for brush in bpy.data.brushes:
        previews.append((brush.name, brush.name, "", brush.preview.icon_id, index))
        index += 1
    pcoll = preview_collections["main"]
    pcoll.brush_selection_previews = previews
    return pcoll.brush_selection_previews

class BrushSelectionPanel(bpy.types.Panel):
    """Creates a new panel for brush selection with categories."""
    bl_label = "Brush Selection"
    bl_idname = "brush_selection_panel"
    bl_category = "Advanced Brushes UI"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'

    def draw(self, context):
        layout = self.layout
        wm = context.window_manager

        row = layout.row()
        row.template_icon_view(wm, "brush_selection_previews")

        row = layout.row()
        row.prop(wm, "brush_selection_previews")

class BrushSelectionPanelReload(bpy.types.Operator):
    """Reload brush selection panel brushes."""
    bl_label = "Reload brush selection panel"
    bl_idname = "brush_selection_panel_reload"

#This is where the previews are stored
preview_collections = {}

def registerBrushSelectionPanel():
    WindowManager.brush_selection_previews = EnumProperty(
    pcoll = bpy.utils.previews.new()
    pcoll.brush_selection_previews = ()
    preview_collections["main"] = pcoll

It finds the brushes just fine, but doesn't actually show any preview images, just blank spaces where the images should be. Any ideas why?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.