0
$\begingroup$

I need to render a cyclic animation of an object-armature from the command line. At the moment I am stack on how to repeat the keyframes, ie how to copy the keyframes of the first time points and paste them at the end of the animation the same object. I was able to do that with 2 different functions. One uses 'NLA_EDITOR':

def extend_cyclic_animation_nla(obj, n_repeatitions):
    
    for obj_i in bpy.data.objects:
        obj_i.select = False

    bpy.context.area.type = 'NLA_EDITOR'
    bpy.ops.nla.action_pushdown(channel_index=1)
    obj.animation_data.nla_tracks["NlaTrack"].strips["Armature|mixamo.com|Layer0"].repeat = n_repeatitions
    bpy.context.area.type = 'TEXT_EDITOR'

The second function uses 'DOPESHEET_EDITOR':

def extend_cyclic_animation_dopesheet(obj, n_repeatitions, frame_end):

    for obj_i in bpy.data.objects:
        obj_i.select = False
    
    bpy.context.area.type = 'DOPESHEET_EDITOR'
    bpy.context.space_data.dopesheet.show_only_selected = True

    obj.select = True
    bpy.ops.action.copy()
    bpy.context.scene.frame_current = frame_end
    for i in range(n_repeatitions):
        
        bpy.ops.action.paste()
        bpy.context.scene.frame_current += frame_end  

    bpy.context.space_data.dopesheet.show_only_selected = False
    bpy.context.scene.frame_current = tmp
    bpy.context.area.type = 'TEXT_EDITOR'

My problem is that they only work when I run them from the blender window. When I run them from the command line I get an error. the reason is that when I run the code from the command line in the background bpy.context.area seems to be set to None and None does not have an attribute 'type'. The error is:

bpy.context.area.type = 'DOPESHEET_EDITOR'
AttributeError: 'NoneType' object has no attribute 'type'

So, My question is given an object with a cyclic animation data, how can I copy (or repeat) the keyframes of that object and paste them at the end of the same animation from the command line? I am using blender 2.79.

$\endgroup$
0
$\begingroup$

Maybe it'll help you

**>>In the Timeline panel, display the layer property containing the keyframes you want to copy.

Select one or more keyframes.

Choose Edit > Copy.

In the Timeline panel containing the destination layer, move the current-time indicator to the point in time where you want the keyframes to appear.**

$\endgroup$
1
  • $\begingroup$ Thanks for helping. But I am talking about how to code it (without opening the blender window). $\endgroup$ – Carmelo Calafiore Sep 26 '20 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.