Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. bl_info = {
  2. "name": "Toggle Ghost Frames Visibility",
  3. "description": "Re-assignable hotkey for toggling visibility of Ghost Frames for current Armature.",
  4. "author": "Ferdinand Joseph Fernandez",
  5. "version": (1, 0),
  6. "location": "Press F while in 3d View (whether in Pose Mode or in Object Mode), or while in Dopesheet",
  7. "support": "TESTING",
  8. "category": "Animation",
  9. }
  10.  
  11. import bpy
  12.  
  13. def is_in_visible_layer(ob):
  14. ob_layers = ob.layers
  15. scene_layers = bpy.context.scene.layers
  16.  
  17. for layer_index in range(len(ob_layers)):
  18. if ob_layers[layer_index] == True and scene_layers[layer_index] == True:
  19. return True
  20.  
  21. return False
  22.  
  23. class ToggleGhostFrames(bpy.types.Operator):
  24. """Toggle Ghost Frames"""
  25. bl_idname = "animation.toggle_ghost_frames"
  26. bl_label = "Toggle Ghost Frames"
  27. bl_options = {'REGISTER', 'UNDO'}
  28.  
  29. def execute(self, context):
  30. ob = context.object
  31.  
  32. if ob.type != 'ARMATURE':
  33. # Selected wasn't an armature.
  34. # Search whole scene for the first
  35. # armature that isn't hidden via the outliner,
  36. # and is in a layer that is currently visible.
  37. for scene_ob in bpy.context.scene.objects:
  38. if scene_ob.type != 'ARMATURE' or scene_ob.hide == True or is_in_visible_layer(scene_ob) == False:
  39. continue
  40.  
  41. ob = scene_ob
  42. break
  43.  
  44. if ob.type == 'ARMATURE':
  45. armature = ob.data
  46.  
  47. if armature.ghost_type == "CURRENT_FRAME":
  48. armature.ghost_type = "RANGE"
  49. elif armature.ghost_type == "RANGE":
  50. armature.ghost_type = "CURRENT_FRAME"
  51.  
  52. return {'FINISHED'}
  53.  
  54. # keymaps are stored here so they can be accessed after registration
  55. toggle_ghost_addon_keymaps = []
  56.  
  57. def register():
  58. bpy.utils.register_class(ToggleGhostFrames)
  59.  
  60. # hotkey registration
  61. wm = bpy.context.window_manager
  62. kc = wm.keyconfigs.addon
  63.  
  64. if kc:
  65. keymap_pose_toggle_ghost = kc.keymaps.new(name='Pose', space_type='EMPTY')
  66. keymap_item_pose_toggle_ghost = keymap_pose_toggle_ghost.keymap_items.new(ToggleGhostFrames.bl_idname, 'F', 'PRESS')
  67.  
  68. keymap_object_toggle_ghost = kc.keymaps.new(name='Object Mode', space_type='EMPTY')
  69. keymap_item_object_toggle_ghost = keymap_object_toggle_ghost.keymap_items.new(ToggleGhostFrames.bl_idname, 'F', 'PRESS')
  70.  
  71. keymap_dope_toggle_ghost = kc.keymaps.new(name='Dopesheet', space_type='DOPESHEET_EDITOR')
  72. keymap_item_dope_toggle_ghost = keymap_dope_toggle_ghost.keymap_items.new(ToggleGhostFrames.bl_idname, 'F', 'PRESS')
  73.  
  74. # add to list so we can unregister afterwards
  75. toggle_ghost_addon_keymaps.append((keymap_pose_toggle_ghost, keymap_item_pose_toggle_ghost))
  76. toggle_ghost_addon_keymaps.append((keymap_object_toggle_ghost, keymap_item_object_toggle_ghost))
  77. toggle_ghost_addon_keymaps.append((keymap_dope_toggle_ghost, keymap_item_dope_toggle_ghost))
  78.  
  79. def unregister():
  80.  
  81. # unregister hotkey
  82. wm = bpy.context.window_manager
  83. kc = wm.keyconfigs.addon
  84. if kc:
  85. for km, kmi in toggle_ghost_addon_keymaps:
  86. #print("Removing hotkey %s" % (kmi.idname))
  87. km.keymap_items.remove(kmi)
  88. # note: don't remove km, as it may contain hotkeys of other add-ons!
  89. #kc.keymaps.remove(km)
  90.  
  91. # clear the list
  92. #addon_keymaps.clear()
  93. del toggle_ghost_addon_keymaps[:]
  94.  
  95. bpy.utils.unregister_class(ToggleGhostFrames)
  96.  
  97. if __name__ == "__main__":
  98. register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement