Skip to content

Instantly share code, notes, and snippets.

@AnomalousUnderdog
Last active August 13, 2017 02:46
Show Gist options
  • Save AnomalousUnderdog/93e723131fb9c851804c6e820e041536 to your computer and use it in GitHub Desktop.
Save AnomalousUnderdog/93e723131fb9c851804c6e820e041536 to your computer and use it in GitHub Desktop.
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:
continue
ob = scene_ob
break
if ob.type == 'ARMATURE':
armature = ob.data
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():
bpy.utils.register_class(ToggleGhostFrames)
# hotkey registration
wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
if kc:
keymap_pose_toggle_ghost = kc.keymaps.new(name='Pose', space_type='EMPTY')
keymap_item_pose_toggle_ghost = keymap_pose_toggle_ghost.keymap_items.new(ToggleGhostFrames.bl_idname, 'F', 'PRESS')
keymap_object_toggle_ghost = kc.keymaps.new(name='Object Mode', space_type='EMPTY')
keymap_item_object_toggle_ghost = keymap_object_toggle_ghost.keymap_items.new(ToggleGhostFrames.bl_idname, 'F', 'PRESS')
keymap_dope_toggle_ghost = kc.keymaps.new(name='Dopesheet', space_type='DOPESHEET_EDITOR')
keymap_item_dope_toggle_ghost = keymap_dope_toggle_ghost.keymap_items.new(ToggleGhostFrames.bl_idname, '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))
km.keymap_items.remove(kmi)
# note: don't remove km, as it may contain hotkeys of other add-ons!
#kc.keymaps.remove(km)
# clear the list
#addon_keymaps.clear()
del toggle_ghost_addon_keymaps[:]
bpy.utils.unregister_class(ToggleGhostFrames)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment