1
$\begingroup$

I would like to get something like in the image:

enter image description here

I have this code, but it moves all the keyframes 10 frames to the right:

import bpy
for action in bpy.data.actions:
   for fcurve in action.fcurves:
     for point in fcurve.keyframe_points:
        point.co.x += 10

I need to move each bone's keyframes 10 more frames than the last one. How could I do that? And how could I access a specific bone's keyframes and move just them?

$\endgroup$
3

2 Answers 2

1
$\begingroup$

Amended code to do somewhat what you want.

Shifts keyframes 0 for first fcurve, 10 for next, 20, 30...

Have made it adjust only the action on the active object.

import bpy

ob = bpy.context.object
ob.animation_data_create()  # lazy way to make animation data exist
action = ob.animation_data.action
if action:
    for i, fcurve in enumerate(action.fcurves):
        for point in fcurve.keyframe_points:
            point.co.x += i * 10

Please use consistent 4 space indent

Re finding which fcurve is which see https://blender.stackexchange.com/a/111326/15543

To order the fcurves firstly by data_path, and secondly by array index eg

pose.bones["bar"].location.x
pose.bones["foo"].location.x
pose.bones["foo"].location.y

Use something like

fcurves = sorted(action.fcurves, key=lambda fc: (fc.data_path, fc.array_index))
$\endgroup$
0
$\begingroup$

I achieved it in this way (it needs polish btw):

import re
import bpy

def lookFor(txt):
    t = re.findall(r'"([^"]*)"', txt)
    return t

amount = 1
boneName = 'null'
boneNameLast = "null"

for action in bpy.data.actions:        
    for fcurve in action.fcurves:         
        boneName = lookFor(fcurve.data_path)

        if  boneName != boneNameLast:
            boneNameLast = lookFor(fcurve.data_path)
            amount = amount + 1

        for point in fcurve.keyframe_points:            
            print(point.co.x)
            point.co.x += amount
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .