diff options
author | lijenstina <lijenstina@gmail.com> | 2017-07-05 02:22:14 +0300 |
---|---|---|
committer | lijenstina <lijenstina@gmail.com> | 2017-07-05 02:22:14 +0300 |
commit | 99ed610784b804c175d9e189d9a1b3036973ed61 (patch) | |
tree | 9865ee8d7e95d9747a349409139e0849db6d1d60 /space_view3d_pie_menus/pie_origin.py | |
parent | 759595b17b3a4b04f800d2c12e2af80aa63e4c29 (diff) |
3D Viewport Pie Menus: Cleanup, refactor, fix key register
Bumped version to 1.1.5
Pep8 cleanup
Remove the pie_origin_cursor.py since it is not needed anymore
Part of the T51547:
refactor the key unregister code so it matches the official pies
Note: using this code was crashing blender because of Bool Tool
key registration that left out some lingering keys on unregister
reload
Also there were some wrong calls with the unregister within the
pies themselves
Merge some operators where possible (around 7 less in total)
and use passing arguments instead
Add Enable All / Disable all buttons in the preferences
Comment out the code for authors in the init instead of in
individual scripts
Remove unused imports and cameratoto scene prop
Add an icon at end of registrations line
Fix several crashes with operators being called out of context
Diffstat (limited to 'space_view3d_pie_menus/pie_origin.py')
-rw-r--r-- | space_view3d_pie_menus/pie_origin.py | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/space_view3d_pie_menus/pie_origin.py b/space_view3d_pie_menus/pie_origin.py index f30acf85..84344d7e 100644 --- a/space_view3d_pie_menus/pie_origin.py +++ b/space_view3d_pie_menus/pie_origin.py @@ -21,8 +21,8 @@ bl_info = { "name": "Hotkey: 'Alt Shift O'", "description": "Origin Snap/Place Menu", - # "author": "pitiwazou, meta-androcto", - # "version": (0, 1, 0), + "author": "pitiwazou, meta-androcto", + "version": (0, 1, 1), "blender": (2, 77, 0), "location": "3D View", "warning": "", @@ -38,33 +38,40 @@ from bpy.types import ( # Pivot to selection - - class PivotToSelection(Operator): bl_idname = "object.pivot2selection" bl_label = "Pivot To Selection" bl_description = "Pivot Point To Selection" bl_options = {'REGISTER', 'UNDO'} + @classmethod + def poll(cls, context): + return context.active_object is not None + def execute(self, context): saved_location = context.scene.cursor_location.copy() bpy.ops.view3d.snap_cursor_to_selected() bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.origin_set(type='ORIGIN_CURSOR') context.scene.cursor_location = saved_location - return {'FINISHED'} -# Pivot to Bottom + return {'FINISHED'} +# Pivot to Bottom class PivotBottom(Operator): bl_idname = "object.pivotobottom" bl_label = "Pivot To Bottom" - bl_description = "Set the Pivot Point To Lowest Point" + bl_description = ("Set the Pivot Point To Lowest Point\n" + "Needs an Active Object of the Mesh type") bl_options = {'REGISTER', 'UNDO'} - def execute(self, context): + @classmethod + def poll(cls, context): + obj = context.active_object + return obj is not None and obj.type == "MESH" + def execute(self, context): bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.transform_apply(location=True, rotation=True, scale=True) bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY') @@ -82,11 +89,11 @@ class PivotBottom(Operator): o.location.z += a bpy.ops.object.mode_set(mode='EDIT') - return {'FINISHED'} -# Pie Origin/Pivot - Shift + S + return {'FINISHED'} +# Pie Origin/Pivot - Shift + S class PieOriginPivot(Menu): bl_idname = "origin.pivotmenu" bl_label = "Origin Menu" @@ -100,28 +107,37 @@ class PieOriginPivot(Menu): pie.operator("object.origin_set", text="Origin to Center of Mass", icon='BBOX').type = 'ORIGIN_CENTER_OF_MASS' # 6 - RIGHT - pie.operator("object.origin_set", text="Origin To 3D Cursor", icon='CURSOR').type = 'ORIGIN_CURSOR' + pie.operator("object.origin_set", text="Origin To 3D Cursor", + icon='CURSOR').type = 'ORIGIN_CURSOR' # 2 - BOTTOM - pie.operator("object.pivotobottom", text="Origin to Bottom", icon='TRIA_DOWN') + pie.operator("object.pivotobottom", text="Origin to Bottom", + icon='TRIA_DOWN') # 8 - TOP - pie.operator("object.pivot2selection", text="Origin To Selection", icon='SNAP_INCREMENT') + pie.operator("object.pivot2selection", text="Origin To Selection", + icon='SNAP_INCREMENT') # 7 - TOP - LEFT - pie.operator("object.origin_set", text="Geometry To Origin", icon='BBOX').type = 'GEOMETRY_ORIGIN' + pie.operator("object.origin_set", text="Geometry To Origin", + icon='BBOX').type = 'GEOMETRY_ORIGIN' # 9 - TOP - RIGHT - pie.operator("object.origin_set", text="Origin To Geometry", icon='ROTATE').type = 'ORIGIN_GEOMETRY' + pie.operator("object.origin_set", text="Origin To Geometry", + icon='ROTATE').type = 'ORIGIN_GEOMETRY' else: # 4 - LEFT pie.operator("object.origin_set", text="Origin to Center of Mass", icon='BBOX').type = 'ORIGIN_CENTER_OF_MASS' # 6 - RIGHT - pie.operator("object.origin_set", text="Origin To 3D Cursor", icon='CURSOR').type = 'ORIGIN_CURSOR' + pie.operator("object.origin_set", text="Origin To 3D Cursor", + icon='CURSOR').type = 'ORIGIN_CURSOR' # 2 - BOTTOM - pie.operator("object.pivot2selection", text="Origin To Selection", icon='SNAP_INCREMENT') + pie.operator("object.pivot2selection", text="Origin To Selection", + icon='SNAP_INCREMENT') # 8 - TOP - pie.operator("object.origin_set", text="Origin To Geometry", icon='ROTATE').type = 'ORIGIN_GEOMETRY' + pie.operator("object.origin_set", text="Origin To Geometry", + icon='ROTATE').type = 'ORIGIN_GEOMETRY' # 7 - TOP - LEFT - pie.operator("object.origin_set", text="Geometry To Origin", icon='BBOX').type = 'GEOMETRY_ORIGIN' + pie.operator("object.origin_set", text="Geometry To Origin", + icon='BBOX').type = 'GEOMETRY_ORIGIN' classes = ( @@ -136,29 +152,26 @@ addon_keymaps = [] def register(): for cls in classes: bpy.utils.register_class(cls) - wm = bpy.context.window_manager + wm = bpy.context.window_manager if wm.keyconfigs.addon: # Origin/Pivot km = wm.keyconfigs.addon.keymaps.new(name='3D View Generic', space_type='VIEW_3D') kmi = km.keymap_items.new('wm.call_menu_pie', 'O', 'PRESS', shift=True, alt=True) kmi.properties.name = "origin.pivotmenu" -# kmi.active = True addon_keymaps.append((km, kmi)) def unregister(): for cls in classes: bpy.utils.unregister_class(cls) - wm = bpy.context.window_manager + wm = bpy.context.window_manager kc = wm.keyconfigs.addon if kc: - km = kc.keymaps['3D View Generic'] - for kmi in km.keymap_items: - if kmi.idname == 'wm.call_menu_pie': - if kmi.properties.name == "origin.pivotmenu": - km.keymap_items.remove(kmi) + for km, kmi in addon_keymaps: + km.keymap_items.remove(kmi) + addon_keymaps.clear() if __name__ == "__main__": |