I want to know how to create a menu with previews for an add-on. Until now I know that this is related with the bpy.utils.preview. I'm making an add-on that appends objects from a .blend file, I know how to append objects but what I want to do is to create a menu with previews of the objects /(similar to the matcaps menu - see below), select them and then press an "import button" to append the object.

$\begingroup$Add some more details and I will be glad to help. I'm not quite sure what you mean by "menu with previews that executes a class when a preview is pressed". Maybe add pictures or expand your description so others can understand.$\endgroup$
– Nathan CraddockFeb 23 '16 at 1:45

$\begingroup$Yes sure. Sorry this is my first question on this site :/$\endgroup$
– Alejandro TorresFeb 23 '16 at 2:54

$\begingroup$Thanks! I will take a look and see if I can help. Do you already have images for the previews, or do you need the script to render for you..$\endgroup$
– Nathan CraddockFeb 24 '16 at 17:07

$\begingroup$I already have them, I just want a way to load each image with an specific id that I can write and track for future functions$\endgroup$
– Alejandro TorresFeb 24 '16 at 17:50

$\begingroup$Sorry that it took so long! I got it working! (finally) :)$\endgroup$
– Nathan CraddockMar 1 '16 at 22:47

1 Answer
1

By analyzing the two provided scripts, as well as the free version of Pro Lighting: Skies I was able to understand how to create a previews menu.

Here is my script that I commented in if you want to study it.
If you run it in Blender's text editor, it will create a panel at the bottom of the Object properties area.

The key parts of what you want to do are:

Create a property collection

This happens in the register function so only one is created. Because you want the the images folder to be predefined, we hard-code the location inside of the script. You also set a globally defined preview_collections variable to hold the collection. Then you create an EnumProperty to hold the images. This has a function to generate the images from the folder.

Access the values

Or however else you named it. Then you can use bpy.context.Scene.my_thumbnails to access the currently selected image name. From there you can create an append button to append from a file based on the image name.

Using in an Addon

To use this method in an addon, you need to change a line in the Previews.py file. Instead of getting the location of the images folder based on the current .blend file, you need to get it based on the location of the addon. So change