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 visibility of Ghost Frames for current Armature.
bl_info = {
"name": "Toggle Ghost Frames Visibility",
"description": "Re-assignable hotkey for toggling visibility of Ghost Frames for current Armature.",
"author": "Ferdinand Joseph Fernandez",
"version": (1, 0),
"location": "Press F while in 3d View (whether in Pose Mode or in Object Mode), or while in Dopesheet",
"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 ToggleGhostFrames(bpy.types.Operator):
"""Toggle Ghost Frames"""
bl_idname = "animation.toggle_ghost_frames"
bl_label = "Toggle Ghost Frames"
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.ghost_type == "CURRENT_FRAME":
armature.ghost_type = "RANGE"
elif armature.ghost_type == "RANGE":
armature.ghost_type = "CURRENT_FRAME"
return {'FINISHED'}
# keymaps are stored here so they can be accessed after registration
toggle_ghost_addon_keymaps = []
def register():
# hotkey registration
wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
if kc:
keymap_pose_toggle_ghost ='Pose', space_type='EMPTY')
keymap_item_pose_toggle_ghost =, 'F', 'PRESS')
keymap_object_toggle_ghost ='Object Mode', space_type='EMPTY')
keymap_item_object_toggle_ghost =, 'F', 'PRESS')
keymap_dope_toggle_ghost ='Dopesheet', space_type='DOPESHEET_EDITOR')
keymap_item_dope_toggle_ghost =, 'F', 'PRESS')
# add to list so we can unregister afterwards
toggle_ghost_addon_keymaps.append((keymap_pose_toggle_ghost, keymap_item_pose_toggle_ghost))
toggle_ghost_addon_keymaps.append((keymap_object_toggle_ghost, keymap_item_object_toggle_ghost))
toggle_ghost_addon_keymaps.append((keymap_dope_toggle_ghost, keymap_item_dope_toggle_ghost))
def unregister():
# unregister hotkey
wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
if kc:
for km, kmi in toggle_ghost_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 toggle_ghost_addon_keymaps[:]
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment