0
$\begingroup$

I write an exporter to retrieve the pose bone matrix for every frame.

The concept looks like this, the code is called from an exporter class via an operation button in the tool shelf:

for action in actions:
    for frame in range(action.frame_range[1]):
        bpy.context.scene.frame_set(frame)
        context.scene.update()

        for poseBone in armature.pose.bones:
            exportMatrix = poseBone.matrix

However, the exported poseBone.matrix values all have the same values from one frame. I checked in the pyhton console if the values change when i manually change the current frame and they do.

What am I missing to update the pose bone matrix after a frame change?

$\endgroup$
1
  • 1
    $\begingroup$ you're not setting the armature's active action to "action", and "context.scene.update" should probably be "bpy.context.scene.update" $\endgroup$
    – HENDRIX
    Feb 26, 2019 at 14:54

2 Answers 2

2
$\begingroup$

To summerize, I needed to perform these changes:

for action in bpy.data.actions:
    bpy.context.object.animation_data.action = action # sets active action
    for frame in range(numberOfFrames):
        bpy.context.scene.frame_set(frame)
        bpy.context.scene.update()
        for bone in bpy.context.object.data.bones: # instead of armature.pose.bones
            poseBone = armature.pose.bones[bone.name]
$\endgroup$
2
$\begingroup$

Update on the accepted answer for Blender 3+ you would have to go

...
bpy.context.scene.frame_set(frame)
bpy.context.view_layer.update()
...

since bpy.context.scene.update() was removed.

More on the change on this post.

$\endgroup$

You must log in to answer this question.

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