Created
August 13, 2017 03:43
-
-
Save AnomalousUnderdog/95a321a8cad57c541368024e24bf17f2 to your computer and use it in GitHub Desktop.
Adds a label in the 3D View of the name of the Action currently being edited in the Dopesheet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bl_info = { | |
"name": "Show Action Name in 3D View", | |
"description": "Adds a label in the 3D View of the name of the Action currently being edited in the Dopesheet.", | |
"author": "Ferdinand Joseph Fernandez", | |
"version": (1, 0), | |
"location": "", | |
"support": "TESTING", | |
"category": "Animation", | |
} | |
import bpy, bgl, blf | |
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 DrawingClass: | |
def start(self, context): | |
self.space = bpy.types.SpaceView3D | |
self.area_id = "VIEW_3D" | |
self.region_id = "WINDOW" | |
self.handle = self.space.draw_handler_add( | |
self.draw_text_callback,(context,), | |
self.region_id, "POST_PIXEL") | |
self.area = None | |
self.dopesheet_area = None | |
def draw_text_callback(self, context): | |
text = None | |
# if selected object has an action, use that | |
if (bpy.context.active_object is not None and bpy.context.active_object.animation_data is not None and bpy.context.active_object.animation_data.action is not None): | |
text = bpy.context.active_object.animation_data.action.name | |
# if dopesheet is open and has an action, use that | |
if (self.dopesheet_area is None): | |
# loop through areas | |
# get the dopesheet | |
for area in bpy.context.screen.areas: | |
if area.type == "DOPESHEET_EDITOR": | |
self.dopesheet_area = area | |
break | |
if (self.dopesheet_area is not None): | |
action = self.dopesheet_area.spaces[0].action | |
if (action is not None): | |
text = action.name | |
# if scene has an armature that is visisble in the 3d view and is using an action, use that | |
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 | |
if (scene_ob.animation_data is not None and scene_ob.animation_data.action is not None): | |
text = scene_ob.animation_data.action.name | |
break | |
if (text is None): | |
return | |
# determine text pos and size | |
font_id = 0 # 0 is default font | |
blf.size(font_id, 11, 72) | |
#label_size = blf.dimensions(font_id, text) | |
text_x = 68 | |
text_y = 25 | |
#padding = 5 | |
#text_x = 100 | |
#if (self.area is not None): | |
# # alight to right edge | |
# text_x = self.area.width - label_size[0] - 15 | |
#text_y = 27 # above scrollbar | |
# draw the text's bg | |
#bgl.glPushAttrib(bgl.GL_ENABLE_BIT) | |
# glPushAttrib is done to return everything to normal after drawing | |
#bgl.glColor4f(0,0,0,0.8) | |
#bgl.glEnable(bgl.GL_BLEND) | |
#bgl.glBegin(bgl.GL_QUADS) | |
# bgl.glVertex2f(text_x-padding, text_y-padding) | |
# bgl.glVertex2f(text_x-padding, text_y+label_size[1]+padding) | |
# bgl.glVertex2f(text_x+label_size[0]+padding, text_y+label_size[1]+padding) | |
# bgl.glVertex2f(text_x+label_size[0]+padding, text_y-padding) | |
# bgl.glEnd() | |
# bgl.glPopAttrib() | |
# draw the text | |
bgl.glPushAttrib(bgl.GL_COLOR_BUFFER_BIT) | |
bgl.glColor4f(0.8,0.8,0.8,1) | |
blf.position(font_id, text_x, text_y, 0) | |
blf.enable(font_id, blf.SHADOW) | |
blf.shadow(font_id, 5, 0, 0, 0, 1) | |
blf.draw(font_id, text) | |
blf.disable(font_id, blf.SHADOW) | |
bgl.glPopAttrib() | |
def remove_handle(self): | |
self.space.draw_handler_remove(self.handle, self.region_id) | |
dc = DrawingClass() | |
def register(): | |
dc.start(bpy.context) | |
def unregister(): | |
dc.remove_handle() # will remove the handle and stop drawing | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment