I'm writing an export script for an armature (using Blender 3.0.0). In this script, I'm attempting to clear bone roll, then force local bone matrices (bone.matrix_local) to be recomputed before writing to a file, as follows:

bpy.ops.object.mode_set(mode = 'EDIT')

# I could also use bpy.ops.armature.roll_clear()
for editBone in armature.edit_bones:
    editBone.roll = 0

# I've tried this script with and without the following line (setting the armature's node to be active).
bpy.context.view_layer.objects.active = node

This seemingly has no effect, as I've confirmed that exported local bone matrices include roll (rather than zeroing roll first). What am I missing? How can I force the export script to recompute bone matrices immediately?


1 Answer 1


Generally you need to exit edit mode for changes to be applied. It works the same way for meshes actually. For example

# Make sure the armature is the thing you're editing
bpy.context.view_layer.objects.active = arma_ob

# Switch to edit mode
if bpy.context.mode != 'EDIT':

# Clear all rolls
for editBone in arma_ob.data.edit_bones:
    editBone.roll = 0

# Exit edit mode

# Access the new bone.matrix_local here

You must log in to answer this question.

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