display text in viewport

I would like to display text or other graphic element in the viewport when auto-ik is active or not (as well as auto set key frame). Something simple like how the camera name, and selected object are displayed in the upper and lower left hand corners. Or maybe outline the active view port. Any suggestions on how to go about this?

There is a built-in warning for auto-keyframing in the top right corner of the 3D view as you are about to change an already keyframed property of an object (unless you disabled it in the user prefs > editing)

How you could draw a frame if auto ik is enabled:

import bpy
import bgl

def draw_callback_px(self, context):

    if context.object is not None:
        ob = context.object
        if not (ob.type == 'ARMATURE' and
                ob.mode == 'POSE' and
                ob.data.use_auto_ik):
            return

    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 0.5, 0.0, 1.0)
    
    w = 10
    h = w // 2
    bgl.glLineWidth(w)
    x = context.region.width - h
    y = context.region.height - h

    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glVertex2i(h, h)
    bgl.glVertex2i(h, y)
    bgl.glVertex2i(x, y)
    bgl.glVertex2i(x, h)
    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)


class ModalDrawOperator(bpy.types.Operator):
    """Draw a line with the mouse"""
    bl_idname = "view3d.modal_operator"
    bl_label = "Simple Modal View3D Operator"

    def modal(self, context, event):

        if event.type == 'F8':
            bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
            context.area.tag_redraw()
            return {'CANCELLED'}

        return {'PASS_THROUGH'}

    def invoke(self, context, event):
        if context.area.type == 'VIEW_3D':
            # the arguments we pass the the callback
            args = (self, context)
            # Add the region OpenGL drawing callback
            # draw in view space with 'POST_VIEW' and 'PRE_VIEW'
            self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_px, args, 'WINDOW', 'POST_PIXEL')
            context.area.tag_redraw()

            context.window_manager.modal_handler_add(self)
            return {'RUNNING_MODAL'}
        else:
            self.report({'WARNING'}, "View3D not found, cannot run operator")
            return {'CANCELLED'}


def register():
    bpy.utils.register_class(ModalDrawOperator)


def unregister():
    bpy.utils.unregister_class(ModalDrawOperator)

if __name__ == "__main__":
    register()

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        bpy.ops.view3d.modal_operator({'area': area}, 'INVOKE_DEFAULT')
        break

WOW! thanks! Works great. I tried to make it an addon with bl_info - an error came with the last segment of code regarding screen.areas. the error doesn’t happen when running from script editor.

This is much more informative than the auto-key warning. Would be great to have for that too. I guess I’d have to edit the first if statement to make it work with auto keying? Is there a way to inset it if both auto-ik and auto key are on at the same time?

Thanks for posting this.