Files
2026-03-17 15:34:28 -06:00

97 lines
2.4 KiB
Python

bl_info = {
"name": "Side Shelf",
"author": "Jesse Doyle",
"blender": (3, 2, 0),
"description": "E Shelf on the right side N panel",
"category": "Side Tabs"
}
import os
import bpy
import bpy.utils.previews
from os import listdir
from os.path import isfile, join
class NPanel(bpy.types.Panel):
"""Creates a Panel in the 3D view Tools panel"""
bl_idname = "TEST_PT_Panel"
bl_label = "Test"
bl_category = "Shelf"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_context = "objectmode"
def draw(self, context):
layout = self.layout
pcoll = preview_collections["main"]
row = layout.row()
triangle_icon = pcoll["triangle"]
square_icon = pcoll["square"]
row.scale_x = 10.0
row.scale_y = 8.0
row.operator("mesh.primitive_cube_add", text="", icon_value=triangle_icon.icon_id)
row.operator("mesh.primitive_uv_sphere_add", text="", icon_value=square_icon.icon_id,scale=10)
# global variable to store icons in
# custom_icons = None
# def register():
# global custom_icons
# custom_icons = bpy.utils.previews.new()
# for z in list_raw:
# custom_icons.load(z[:-4], os.path.join(directory, z), 'IMAGE')
# bpy.utils.register_class(Panel)
# def unregister():
# global custom_icons
# bpy.utils.previews.remove(custom_icons)
preview_collections = {}
def register():
# Note that preview collections returned by bpy.utils.previews
# are regular py objects - you can use them to store custom data.
pcoll = bpy.utils.previews.new()
# path to the folder where the icon is
# the path is calculated relative to this py file inside the addon folder
directory = os.path.join(os.path.dirname(__file__), "Data", "icons")
list_raw = []
onlyfiles = [f for f in listdir(directory) if isfile(join(directory, f))]
for f in onlyfiles:
if f[-4:] == ".png":
list_raw.append(f)
for z in list_raw:
# load a preview thumbnail of a file and store in the previews collection
pcoll.load(z[:-4], os.path.join(directory, z), 'IMAGE')
preview_collections["main"] = pcoll
bpy.utils.register_class(NPanel)
def unregister():
for pcoll in preview_collections.values():
bpy.utils.previews.remove(pcoll)
preview_collections.clear()
bpy.utils.unregister_class(NPanel)
if __name__ == "__main__":
register()