I want to use the template_icon_view to display a set of images from bpy.data.images. I know there is bpy.utils.preview which has a load function to load in external images. Is it possible to feed a template_icon_view with internal images?

What would be the proper approach to create an enum property with the images?

  • $\begingroup$ Actually, I asked that two weeks ago, here's the answer: blender.stackexchange.com/questions/47504/… $\endgroup$ Mar 9 '16 at 1:10
  • $\begingroup$ Hi Ray, yes.. I have seen this question. My problem is that this thumbnails are generate of external images. I want to use internal images that are not stored somewhere on the harddrive. The bpy.tils.preview module needs external images to generate that previews. $\endgroup$
    – ndee
    Mar 9 '16 at 6:23

Data-blocks store their own previews, so you can access bpy.types.ImagePreview.icon_id

The icon_id can be passed to UI elements that take an icon value.


import bpy
for image in bpy.data.images:
    print(image.name, image.preview.icon_id)

This will print the id of already loaded icons.

One area I'd need to look into is how to generate icons from images. The interface does this automatically, but you may want to generate the images on demand (as far as I can see we don't have a direct API call to do this).

Heres a fully working example of using image previews in Blender's interface.

# Run this script and check the object properties.
import bpy

class ImagePreviewPanel(bpy.types.Panel):
    bl_label = "Image Icons"
    bl_idname = "OBJECT_PT_image_icons"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout
        for image in bpy.data.images:
            layout.label(image.name, icon_value=image.preview.icon_id)
        if not bpy.data.images:
            layout.label("No images!")

def register():

def unregister():

if __name__ == "__main__":
  • $\begingroup$ It seems I have exactly that problem. I get the icon id and the template_icon_view generates the items based on the created enum. But the icons are empty. $\endgroup$
    – ndee
    Mar 9 '16 at 6:59
  • $\begingroup$ The icons should work in enums too, if you have issues here could be different question. $\endgroup$
    – ideasman42
    Mar 9 '16 at 7:20
  • $\begingroup$ I have a question concerning the part how to generate icons from images. Is there a way to manually trigger an icon to be generated? $\endgroup$
    – ndee
    Jul 11 '16 at 20:56
  • $\begingroup$ Unfortunately this method that I find quite obvious and right, does not always generate a preview, it probably depends on the format and size of the image. The blender itself does not seem to generate previews of such images, it seems to happen on some png images in 2k. I think it's a bug or if it's not it creates big problems. $\endgroup$
    – Noob Cat
    Feb 25 at 13:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.