Callback for any command executed? Or any UI created?

Time to share what i decided to go with:

  1. create a function that scrubs all internally created menus and their children, stores in a dict as key = command they run, and value = name of the tool (menuItem label). This dict is stored for the whole session of maya.
  2. create a callback function, that gets the last command that was run with mc.repeatLast(q = True), and then checks if that command exists in the dict that was created in step 1. If so, it throws out the needed info (menu name, command that was run, and some other metrics gathered by default such as dcc version, user, etc) into our telemetry system
  3. attached the callback created in step 2 using om.MCommandMessage.addCommandCallback(). This way has several things other people should keep in mind:
    a) It will get triggered tens of times, after a command is run. so in step 2 in the callback function, to not hamper the processing that much, i have implemented checking if the last command is same as the one before it, i ignore that trigger.
    b) this doesn’t trigger when a script is run from pressing a button in a tool. This was an issue for the goal of this mission, because we might have a tool or two that gathers other tools, as buttons. I have semi-solved this by catching when THAT tool is run, and then running an additional script that adds another action to each one of the clicked signals of the gathered buttons within that tool.
  4. I have then added the function to call all this, into the userSetup.py file, to make sure the callback is registered at the beginning of any Maya session.

This is about it for now. If there’s anything that someone suggests to do differently, don’t hesitate to let me know.

I stress again, that this is a hail mary attempt at some last minute basic telemetry. In no way is this considered to replace actual properly implemented telemetry, and in no way would i recommend this approach, if you have any other option.
For us, it wasn’t feasible at all, to consider touching each tool’s scripts, hence resulting in this situation.

Hope this eventually helps someone ^^

1 Like