Easy enough:
- make a directory for your addon
- put an icons folder in it
- fill the
- make a directory for your addon
- put an icons folder in it
- fill the
operator_behaviours
list with the names of your icons (minus their filetype)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import bpy | |
import bpy.utils.previews | |
from bpy.types import Menu, Operator | |
from bpy.props import StringProperty | |
bl_info = { | |
"name": "ViewPort Navigator Pie Menu (Demo - with custom icons)", | |
"author": "Dealga McArdle", | |
"version": (0, 0, 1), | |
"blender": (2, 7, 5), | |
"location": "Viewport", | |
"description": "Adds pie menu with viewport navigation options.", | |
"wiki_url": "", | |
"tracker_url": "", | |
"category": "3D View"} | |
operator_behaviours = ['anchor', 'pinch', 'rotator'] | |
preview_collections = {} | |
class VIEW3D_PM_NAV_ops(Operator): | |
bl_idname = "view3d.pie_menu_navigator" | |
bl_label = "Quickly Navigate 3dview" | |
b_type = StringProperty() | |
def execute(self, context): | |
if not self.b_type: | |
return {'CANCELLED'} | |
print('action path:', self.b_type) | |
return {'FINISHED'} | |
class VIEW3D_MT_PIE_Menu_Nav(Menu): | |
bl_label = "Navigate" | |
bl_idname = "view3d.pie_menu_base" | |
def draw(self, context): | |
pcoll = preview_collections["nav_main"] | |
view_ops = "view3d.pie_menu_navigator" | |
pie = self.layout.menu_pie() | |
for behaviour in operator_behaviours: | |
icon = pcoll[behaviour] | |
pie.operator(view_ops, text=behaviour, icon_value=icon.icon_id).b_type = behaviour | |
def register(): | |
import bpy.utils.previews | |
pcoll = bpy.utils.previews.new() | |
icons_dir = os.path.join(os.path.dirname(__file__), "icons") | |
for img in operator_behaviours: | |
full_img_name = (img + ".png") | |
img_path = os.path.join(icons_dir, full_img_name) | |
pcoll.load(img, img_path, 'IMAGE') | |
preview_collections["nav_main"] = pcoll | |
bpy.utils.register_class(VIEW3D_PM_NAV_ops) | |
bpy.utils.register_class(VIEW3D_MT_PIE_Menu_Nav) | |
def unregister(): | |
for pcoll in preview_collections.values(): | |
bpy.utils.previews.remove(pcoll) | |
preview_collections.clear() | |
bpy.utils.unregister_class(VIEW3D_MT_PIE_Menu_Nav) | |
bpy.utils.unregister_class(VIEW3D_PM_NAV_ops) | |
if __name__ == "__main__": | |
register() |