Skip to content

Instantly share code, notes, and snippets.

Last active August 13, 2017 02:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Re-assignable hotkey for toggling between Rest and Pose Mode for selected Armature.
bl_info = {
"name": "Toggle Armature Rest/Pose",
"description": "Re-assignable hotkey for toggling between Rest and Pose Mode for selected Armature.",
"author": "Ferdinand Joseph Fernandez",
"version": (1, 0),
"location": "Press Shift-Q while in 3d View, and in Pose Mode of an Armature",
"support": "TESTING",
"category": "Animation",
import bpy
def is_in_visible_layer(ob):
ob_layers = ob.layers
scene_layers = bpy.context.scene.layers
for layer_index in range(len(ob_layers)):
if ob_layers[layer_index] == True and scene_layers[layer_index] == True:
return True
return False
class RestPoseToggle(bpy.types.Operator):
"""Toggle Rest/Pose"""
bl_idname = "animation.rest_pose_toggle"
bl_label = "Toggle Rest/Pose"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
ob = context.object
if ob.type != 'ARMATURE':
# Selected wasn't an armature.
# Search whole scene for the first
# armature that isn't hidden via the outliner,
# and is in a layer that is currently visible.
for scene_ob in bpy.context.scene.objects:
if scene_ob.type != 'ARMATURE' or scene_ob.hide == True or is_in_visible_layer(scene_ob) == False:
ob = scene_ob
if ob.type == 'ARMATURE':
armature =
if armature.pose_position == 'POSE':
armature.pose_position = 'REST'
armature.pose_position = 'POSE'
return {'FINISHED'}
# keymaps are stored here so they can be accessed after registration
rest_pose_toggle_addon_keymaps = []
def register():
# hotkey registration
wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
if kc:
keymap_pose_rest_pose_toggle ='Pose', space_type='EMPTY')
keymap_item_pose_rest_pose_toggle ="animation.rest_pose_toggle", 'Q', 'PRESS', shift=True)
keymap_object_rest_pose_toggle ='Object Mode', space_type='EMPTY')
keymap_item_object_rest_pose_toggle ="animation.rest_pose_toggle", 'Q', 'PRESS', shift=True)
# add to list so we can unregister afterwards
rest_pose_toggle_addon_keymaps.append((keymap_pose_rest_pose_toggle, keymap_item_pose_rest_pose_toggle))
rest_pose_toggle_addon_keymaps.append((keymap_object_rest_pose_toggle, keymap_item_object_rest_pose_toggle))
def unregister():
# unregister hotkey
wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
if kc:
for km, kmi in rest_pose_toggle_addon_keymaps:
#print("Removing hotkey %s" % (kmi.idname))
# note: don't remove km, as it may contain hotkeys of other add-ons!
# clear the list
del rest_pose_toggle_addon_keymaps[:]
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment