old mouseAnimator ... Api change

Searching for … I found a mouseAnimator script coming from www.modelanimator.com/…/blendMouseAnimator.py (link will probably not work,
Found by ““region.callback_add”” …

After detecting Api changes and … I got it working :wink:


import bpy
import bgl
import blf
import time

def draw_callback_px(self, context, event ):

    # draw some text
    blf.size(0,20, 50)
    blf.position(0,60, 20, 0)
    ch = str (event.mouse_x)
    blf.draw(0, ch )

    blf.position(0,150, 20, 0)
    ch = str (event.mouse_y)
    blf.draw(0, ch )
    
    if ( bpy.context.active_object != None ):
        bpy.context.active_object.location.x =  event.mouse_x/100-3
        bpy.context.active_object.location.y =  event.mouse_y/100

#        cur = bpy.context.scene.current_frame
        cur = bpy.context.scene.frame_current
        bpy.context.scene.frame_current = cur+1
        bpy.ops.anim.keyframe_insert_menu(type=-4)    


class MouseAnimator(bpy.types.Operator):
    '''Record animation with the mouse'''
    bl_idname = "view3d.mouseAnimator"
    bl_label = "Mouse Animator"

    record = False 

    def modal(self, context, event):
    
        context.area.tag_redraw() 
        if event.type == ('F7'):
            context.region.callback_remove(self._handle)
            return {'CANCELLED'}

        return {'PASS_THROUGH'}

    def invoke(self, context, event):
        if context.area.type == 'VIEW_3D':
            context.manager.add_modal_handler(self)
            self._handle = context.region.callback_add(draw_callback_px, (self, context, event ), 'POST_PIXEL')      
            return {'RUNNING_MODAL'}
        else:
            self.report({'WARNING'}, "View3D not found, cannot run operator")
            return {'CANCELLED'}


def register():
    bpy.types.register(MouseAnimator)


def unregister():
    bpy.types.unregister(MouseAnimator)


if __name__ == "__main__":
    register()

Put it in the a text , and run it.
Find in the T -menu 'mous… and take it.
aktivate the button move the mouse (coordinates are shown below!) and stop by pushing F7.
Alt AKEY (eventually setting the end of the ani) and the animation runs (hi hi).