Quick question: Dissolving Keyframes?

Hi everyone. Yesterday I got stuck in something there I’m quite sure we could do early in the days.

It is the ability to dissolve in beteween keyframes gradually until a point you’re happy.
For example: when we had a physics simulation baked I was able to delete big part of the keyframes while keeping the extremes giving me more the possibility to customize the animation aftterwards with easy.

I couldn’t found this feature… I’m believe it was accessible by the Graph Editor before… Anybody knows this trick? Or it was an addon that I’m missing?

Reply to myself: :sweat_smile:
Its an addon, and its called: Simplify Curves.


Now I would like to run a little script to apply the Simplify Curves to each selected object.

I got this:

import bpy

for obj in bpy.context.selected_objects:

But the problem it just apply the operator to the current active object.
How I’m I suppose to apply for each selected object at once?

This line does not contain any reference to obj, so will not iterate. Without me looking at how you do what you want to do, you need to get the graph from obj and manipulate that, so something like:

obj.(get it's graph).simplify(error = 0.5)

There might be several graphs for each object, so you will need to iterate through them also…

Cheers, Clock.

Thanks for answering.
I wanto to execute:


for each selected object for all the curves available.

The result would be like that:

For now it just work for the active selected object.
As you pointed out I’m missing something…

I’m a little bit closer now:

import bpy

for i in bpy.context.selected_objects:
    bpy.context.view_layer.objects.active = bpy.context.selected_objects[i]

but getting an error: Traceback (most recent call last):
File “<blender_console>”, in
TypeError: list indices must be integers or slices, not Object

if I manually insert a number in bpy.context.selected_objects[i] like bpy.context.selected_objects[4] the correct object is applied the changes… but I’m struggling to iterate it trough all the selected objects… I though puting the [i] It would do… but not.

I have accomplished what I was trying to do. See the results in the graphs:

The code is not elegant cause I have manually set the range for the amount of selected objects. It worked forcing an out of range set as well…

In order work it I have to select all the wanted objects,
then select all the graphs,
then run the script.
In 2 seconds all the graphs are now much more light due to the Simplify f-curves operator at .5 factor set for 1076 objects in the scene. :tipping_hand_man:

If you can set a more elegant code I would like to learn it, please.

import bpy

for i in range(0,1076):
    bpy.context.view_layer.objects.active = bpy.context.selected_objects[i]


You could set the range number with something like this:

rMax = len(bpy.context.selected_objects)

for i in range(0,rMax):
    bpy.context.view_layer.objects.active = bpy.context.selected_objects[i]

There must also be a way to select all the F-Curves, but I am too busy (off flying my plane) now to look at that for you, maybe later today…

Cheers, Clock.

There is, this code should work for you:

import bpy

# Iterate through selected objects
for ob in bpy.context.selected_objects:
    bpy.context.scene.objects.active = ob
    # Get F-Curves and iterate through to select them
    fCurves = ob.animation_data.action.fcurves
    for fc in fCurves:
        fc.select = True
    # Simplify F-Curves

Before running script:


I did not include the last line in my script above, as I don’t actually want to do this to my blend file…

Cheers, Clock. :beers: