Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/__init__.py
Created June 14, 2015 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/2b09e53cccaa4427302a to your computer and use it in GitHub Desktop.
Save zeffii/2b09e53cccaa4427302a to your computer and use it in GitHub Desktop.
Pie menu with custom icons
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment