I want to execute a custom python script before executing a Blender method that I call using a shortcut. What I could like is to add some scripting before changing the active camera while I use the Ctrl+Numpad 0 shortcut.

I am aware of bpy.app.handlers which do not contain what I need (only render, file load, etc handlers).

Do you advise me to define my own, similar shortcut in the definition of the operator, that would first make the call to my function and then to blender's operator ? Or is there a way to enable my script before blender operator using a handler similar to above ?

km = bpy.context.window_manager.keyconfigs.addon.keymaps.new(name='3D View', space_type='VIEW_3D')
kmi = km.keymap_items.new(idname = 'camera.test_function',
        type = 'NUMPAD_0, ctrl=True, alt=True, value='PRESS')  

Thanks in advance, Jonathan

  • 2
    $\begingroup$ For a couple of operators, defining your own operator that calls both is probably easiest. Also have a look at blender.stackexchange.com/questions/3032/… , the answers explain how to define macros that include multiple ops. $\endgroup$
    – batFINGER
    Commented Sep 17, 2015 at 10:37


You must log in to answer this question.

Browse other questions tagged .