How to tell if a blender operator executed?

Hi all,

I’m looking for a way to know if one of blender’s internal operators executed. Specifically, I want to know if an object/bone has been scaled, rotated, or moved.

Here’s what I am really looking for: creating a smart auto key framing tool.

When animating using blender’s auto key framing, when an object/bone is moved, scaled, or rotated, blender automatically inserts key frames for the loc/rot/scale. That’s 9 key frames (if using euler rotations, 10 keys if quaternion rotation) inserted in the dopesheet on 9 channels, 3 loc, 3 rot, 3 scale channels. I’d like to reduce the number of key frames added from 9 (or 10) down to just the number of key frames needed.

For example; animating the hands of a clock, you’d have 2 hands that can be rotated on their x-axis only. The location, scale, and y & z rotations are locked and can’t be changed or animated. Blender’s auto keying will insert key frames for every channel, so you get 9 key frames when only changing the x rotation, or only needing 1 key frame.

It’s not so much a big deal when working with the dopesheet, but when it comes to tweaking animation curves in the f-curve editor, you deal with 9 animation curves when only 1 channel (or curve) has changed, the x-axis.

I’d like a tool that only inserts key frames on channels that have changed. Best way to do that, as I see it, is to find out when these operators execute:


bpy.ops.transform.translate()
bpy.ops.transform.rotate()
bpy.ops.transform.resize()

Then insert key frames only on channels that aren’t locked down.

I’m sure I can write an operator to insert the key frames for channels that aren’t locked, but what I can’t figure out is how to execute the operator… How would I know when an object/bone has changed?

Thanks,
Randy

i believe most operators return either ‘FINISHED’ or ‘CANCELED’ to report how they ran

every operator must return a set in fact, possible return values:

  • FINISHED: completed successful
  • CANCELLED: execution was aborted
  • PASS_THROUGH: modal operation invoked and events are passed on
  • RUNNING_MODAL: modal operation invoked and events are consumed

Thanks @khalibloo for your help!!!

It appears that I have failed to provide all the information I needed to receive proper help. It frustrates me when I try to help another user and they haven’t provided all the information needed to solve their problem. And here I am committing the same mistake. So I’ll admit to being and idiot, and only having basic python skills.

I’m sure I can write an operator to insert the key frames for channels that aren’t locked, but what I can’t figure out is how to execute the operator… How would I know when an object/bone has changed?

That should really read as:

I can write an operator to insert key frames for me, but how would I execute that operator when one of these blender operators execute:


bpy.ops.transform.translate() 
bpy.ops.transform.rotate() 
bpy.ops.transform.resize()

 

How would I know the above operators executed? How would my script know if a user did something to trigger one of those blender operators? If a user does something to trigger any of those 3 operators, how would my script know that happened? A simple if statement like:


if bpy.ops.transform.translate() = FINISHED

or what is needed to know that one of those operators executed?

How can I find out when a user triggers one of those operators?

Thanks for the help,
Randy

what you need is something like

if (bpy.ops.transform.translate() == {‘FINISHED’}) :

to find out if a user triggers something, i think you need app handlers. i haven’t seen a decent example of that anywhere, so maybe someone else could help you with that