forked from Exairnous/Advanced-UI-Menus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pivot_menu.py
78 lines (63 loc) · 3.5 KB
/
pivot_menu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from .Utils.core import *
# adds a pivot point menu
class PivotPointMenu(bpy.types.Menu):
bl_label = "Pivot Point"
bl_idname = "VIEW3D_MT_pivot_point"
def draw(self, context):
menu = Menu(self)
# get set pivot modes based on spacetype
if context.space_data.type == 'VIEW_3D':
pivot_modes = [["Median Point", "'MEDIAN_POINT'", "ROTATECENTER"],
["3D Cursor", "'CURSOR'", "CURSOR"],
["Individual Origins", "'INDIVIDUAL_ORIGINS'", "ROTATECOLLECTION"],
["Active Element", "'ACTIVE_ELEMENT'", "ROTACTIVE"],
["Bounding Box Center", "'BOUNDING_BOX_CENTER'", "ROTATE"]]
if context.space_data.type == 'GRAPH_EDITOR':
pivot_modes = [["2D Cursor", "'CURSOR'", "CURSOR"],
["Individual Centers", "'INDIVIDUAL_ORIGINS'", "ROTATECOLLECTION"],
["Bounding Box Center", "'BOUNDING_BOX_CENTER'", "ROTATE"]]
if context.space_data.type == 'IMAGE_EDITOR':
pivot_modes = [["Median Point", "'MEDIAN'", "ROTATECENTER"],
["2D Cursor", "'CURSOR'", "CURSOR"],
["Individual Origins", "'INDIVIDUAL_ORIGINS'", "ROTATECOLLECTION"],
["Bounding Box Center", "'CENTER'", "ROTATE"]]
# create menu
for mode in pivot_modes:
prop = menu.add_item().operator("wm.context_set_value", mode[0], icon=mode[2])
prop.value = mode[1]
prop.data_path = "space_data.pivot_point"
if bpy.context.space_data.pivot_point == mode[1][1:-1]:
menu.current_item.enabled = False
# if your in 3D View and in object or pose mode add the manip center points
# menu
if context.space_data.type == 'VIEW_3D':
if get_mode() in [object_mode, pose]:
menu.add_item().separator()
if not bpy.context.space_data.use_pivot_point_align:
prop = menu.add_item().operator("wm.context_set_value",
"Enable Manipulate center points",
icon="ALIGN")
prop.value = "True"
prop.data_path = "space_data.use_pivot_point_align"
else:
prop = menu.add_item().operator("wm.context_set_value",
"Disable Manipulate center points",
icon="ALIGN")
prop.value = "False"
prop.data_path = "space_data.use_pivot_point_align"
### ------------ New hotkeys and registration ------------ ###
addon_keymaps = []
def register():
# create the global menu hotkey
wm = bpy.context.window_manager
modes = {'Object Non-modal':'EMPTY', 'Graph Editor':'GRAPH_EDITOR', 'Image':'IMAGE_EDITOR'}
for mode, space in modes.items():
km = wm.keyconfigs.addon.keymaps.new(name=mode, space_type=space)
kmi = km.keymap_items.new('wm.call_menu', 'PERIOD', 'PRESS')
kmi.properties.name = 'VIEW3D_MT_pivot_point'
addon_keymaps.append((km, kmi))
def unregister():
# remove keymaps when add-on is deactivated
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()