Logging Operators?

Using python, Is there any way to log all operators as they’re called? I want to write a script which records the usage frequency of operators so the user can keyboard-map the most frequently used to the most convenient keyboard area.

Hi,

I slapped together something to do this a while back, put the count code in just then.

Note it only logs operators that register as the context.active_operator


import bpy

op = None
count_log = {}

def log_operator(scene):
    global op
    context = bpy.context
    if op != context.active_operator:
        op = context.active_operator
        opname = "bpy.ops.%s" % op.bl_idname.replace("_OT_", ".").lower()
        if opname not in count_log:
            count_log[opname] = 1
        else:
            count_log[opname] += 1
        print("------------------------------------------------------")
        print("Operator %s [count:%d]" % (opname, count_log[opname]))
        print("------------------------------------------------------")

        for key in op.bl_rna.properties.keys():
            print("	%s = %s" % (key, eval("op.%s" % key)))
        print("	----------")    
        print("	Properties")
        print("	----------")
        
        for key in op.rna_type.bl_rna.properties.keys():
            print("	%s = %s" % (key, eval("op.%s" % key)))
            
bpy.app.handlers.scene_update_post.append(log_operator)

bpy.app.debug = True

or individually, set these booleans and


bpy.app.debug_events
            debug_ffmpeg
            debug_python
            debug_value
            debug_wm

You will be able to see whats going on in the background, if you start blender from a console / terminal do

blender --help

for a more elaborate list of debug options. ( blender -d or blender --debug) for debug. But you will probably have to do a little bit scraping on your stored log files (i assume you will not want to parse the debug output by hand)

Thanks batFINGER, that’s very helpful. Your script works when I run it from the text editor, but what’s the best way to have it run automatically when blender starts? :confused:

Not going to have a shot at what is the “best” way.

Probably the simplest way is to open a new blender, put the script in the text editor, hit the register checkbox, and save user settings.

Another way is to set it up as an addon and make the handler persistent.

http://www.blender.org/documentation/blender_python_api_2_63_17/bpy.app.handlers.html?highlight=handlers#bpy.app.handlers