As example I made this simplified addon. Instead of having buttons, I want to show it thumbnails. Once a thumbnail is chosen it should activate a class (ADD_OT_cube1 or class ADD_OT_cube2). Here the example with just buttons:
import bpy
# Here comes bl_info
# Add cube 1 to scene
class ADD_OT_cube1(bpy.types.Operator):
bl_idname = 'add.cube1'
bl_description = 'Adds a cube. Blue, small.'
bl_category = 'SuperCube'
bl_label = 'Add Blue Cube'
def execute(self, context):
path = os.path.dirname(__file__) + "/ojbects/cubes.blend\\Collection\\"
object_name = "cube_01"
bpy.ops.wm.append(filename=object_name, directory=path)
return {"FINISHED"}
# Add cube 2 to scene
class ADD_OT_cube2(bpy.types.Operator):
bl_idname = 'add.cube2'
bl_description = 'Adds a cube. Red, Eating a banana.'
bl_category = 'SuperCube'
bl_label = 'Add Grazy Cube'
def execute(self, context):
path = os.path.dirname(__file__) + "/ojbects/cubes.blend\\Collection\\"
object_name = "cube_02"
bpy.ops.wm.append(filename=object_name, directory=path)
return {"FINISHED"}
# The menu in the N-Panel
class ADD_MT_menu(bpy.types.Menu):
bl_label = "Add Cubes"
bl_idname = "ADD_MT_menu"
def draw(self, context):
layout = self.layout
layout.operator("add.cube1")
layout.operator("add.cube2")
# Register Classes
classes = (
ADD_OT_cube1,
ADD_OT_cube2,
ADD_MT_menu)
def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)
def unregister():
from bpy.utils import unregister_class
for cls in classes:
unregister_class(cls)
if __name__ == "__main__":
register()
I hope you can help me out.
There is the ui_previews_dynamic_enum.py template that comes with blender (which I am struggling with to understand i fully) but I don’t need the dynamic part since my previews are already defined. And I wonder how I can make it so that a selection of the thumbnail activates ADD_OT_cube1 or ADD_OT_cube1
And the template ui_previews_custom_icon.py is not what I am looking for because I have more than 20 thumbnails. That would end up in 20 big buttons I suppose.