Bones, keyframes, and animation

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
KainXavier
Posts: 0
Joined: Mon Jan 21, 2013 11:31 pm

Bones, keyframes, and animation

Post by KainXavier » Tue Jan 22, 2013 10:25 pm

Hi, I am writing a model importer and I am bit mystified as to how to animate bones in Blender 2.63 using the Python API. The following code will execute but seemingly produce no animation:

Code: Select all

def create_blenderkeyframes(armature):
    import mathutils
    global model
    
    #Bones can only be transformed in Pose mode.

    for animation in model.animationlist:
        for keyframe in animation.keyframelist:
            for boneindex in range(model.bonecount):
                posebone = armature.pose.bones[boneindex]
                transform = keyframe.transformlist[boneindex]

                if not transform.isvertextransform:
                    posebone.location = transform.loc
                    posebone.rotation_quaternion = transform.rot
                    posebone.keyframe_insert(data_path = 'location',
                                             frame = keyframe.time,
                                             group = animation.name)
                    posebone.keyframe_insert(data_path = 'rotation_quaternion',
                                             frame = keyframe.time,
                                             group = animation.name)

    bpy.ops.object.mode_set(mode = 'OBJECT')
I hope the above code is clear but I can clarify any questions and I greatly appreciate any answers! Thank you!

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

Post by CoDEmanX » Tue Jan 22, 2013 11:43 pm

you should really use the low-level approach, see

http://www.blender.org/documentation/bl ... #animation

operators such as keyframe_insert should work as well, but are too damn slow. Can't tell why your script isn't working without an example file.
I'm sitting, waiting, wishing, building Blender in superstition...

KainXavier
Posts: 0
Joined: Mon Jan 21, 2013 11:31 pm

Post by KainXavier » Wed Jan 23, 2013 5:40 am

CoDEmanX wrote:you should really use the low-level approach, see

http://www.blender.org/documentation/bl ... #animation

operators such as keyframe_insert should work as well, but are too damn slow. Can't tell why your script isn't working without an example file.
Ah, I must have missed that section in the API documentation. Thank you very much! I will try that and post again if I run into any more trouble.

Post Reply