0
$\begingroup$

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
bpy.context.view_layer.update()

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?

$\endgroup$

1 Answer 1

1
$\begingroup$

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':
    bpy.ops.object.mode_set(mode='EDIT')

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

# Exit edit mode
bpy.ops.object.mode_set(mode='OBJECT')

# Access the new bone.matrix_local here
$\endgroup$

You must log in to answer this question.

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