Clean Keyframes Operator Context

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
cav2
Posts: 0
Joined: Wed Jul 31, 2013 10:31 pm

Clean Keyframes Operator Context

Post by cav2 » Wed Jul 31, 2013 10:47 pm

Hey guys,

I'm trying to call the action.clean() operator which removes unnecessary keyframes from the F-curves, but I can't seem to get the context right.
It's funny that this is the same example used on the API's Gotchas page... except the Gotchas page never actually helps out with solving that particular example!

Common sense says I have to be in the DopeSheet Editor or Graph Editor for this to work, so this is my operator call:

Code: Select all

        for area in bpy.context.screen.areas:
            if area.type == 'DOPESHEET_EDITOR':
                bpy.ops.action.clean({'area':area})
                break
I get the following non-descriptive error:

Code: Select all

RuntimeError: Operator bpy.ops.action.clean.poll() failed, context is incorrect
What else do I need to put into my context override to get this to work?

Thanks!

CoDEmanX
Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX » Thu Aug 01, 2013 3:46 am

with 'area' provided, it works for me flawlessly.

you could also change the area.type temporarily to ensure proper context
I'm sitting, waiting, wishing, building Blender in superstition...

cav2
Posts: 0
Joined: Wed Jul 31, 2013 10:31 pm

Post by cav2 » Tue Aug 06, 2013 7:23 pm

Hmmm, I still can't seem to get it work. I think the problem is that in my addon, I load a new blend file immediately before trying to call that operator. I'd bet there's some other initialization stuff Blender has to do first before the poll function can return True.

It's not that big of a deal. I can just do the action.clean() at a different time. Thanks though!

CoDEmanX
Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX » Wed Aug 07, 2013 11:20 pm

hm yeah maybe there's something else, like the mode of the area, not sure though... could you provide a blend with your UI and the script?
I'm sitting, waiting, wishing, building Blender in superstition...

Post Reply