Intercepting Operation Calls

Hi, there’s a way to intercept operation calls? I want to call another operation everytime that someone call a Modal operation (bpy.ops.transform.translate), i need to get a callback when it start and when finish to run a complementary script. Any suggestion?

No, that’s not possible, but you can check the operator log what was run earlier:

bpy.context.window_manager.operators

You shouldn’t undo any of them however, it potentially leads to crashes

I think it can do the job, i will try! Thanks! =D

It don’t work well cause a Modal Operation only update the stack after it execute, i need to get a call for it in the start :(, that way i can only get the last operator used not the actual

You can’t, this behavior is fundamental in the design of operators and the event system. Modal ops consume all events, and an operation can’t be logged when there’s nothing done yet to the actual data.

I understand but at the same time we can want to active some background code when a modal operation trigger ( if the are thread safe or not dependent ). Today we can have operations in background even when modal is running using handlers the only one thing is that we can’t get the right indication of the actual operation called, if it’s a modal we just get the last one… i don’t think is so destructive to have handlers that can interact with native blender functions ( my goal is to change the object visibility when using transformations ).

You can control object visibility if you re-write the transform modal op in python, 'cause both things would happen in a single modal op that receives all events. I assume however, that it would be a lot slower.

I don’t think app handlers and modal ops are carried out simultaneously, but rather at different points in time. Two parallel running modal ops however would probably interfere each other and cause race conditions, but not sure how the internals work here… At least there are couple things in Blender which aren’t thread-safe, and I believe this is a problem for what you try to do (even C maybe).

You can control object visibility if you re-write the transform modal op in python, 'cause both things would happen in a single modal op that receives all events. I assume however, that it would be a lot slower.

I think i can rewrite the hotkeys (G,R,S) to point to another operations ( that will call the transform and call my code), but it will not work if the guy click in the Tool Shelf for a Transform or if it’s using 3D Manipulators. Such a hard problem here :spin:

Can I ask? Why do you want to monitor every operator call? Are you trying to automate some process?

that will call the transform and call my code

Don’t expect it to work for regular operators, non-modal operators are run immediately even if there are several other calls to modal operators before in code. And the modal ops will consume the events, so you can’t keep control over it. If you use two modal ops and a macro, you may be able to hack around the limitations, but it’s not very safe together with Undo.

Done but only works replacing the original hotkeys. Looks there’s no way to replace the manipulator operations or the original tool shelf transform operations with python. It’s not perfect but is enough for now.

Thanks for your comments, help me to clarify it problem