I need to reset my armature to the rest position with a python code. I could do it normally with but bpy.ops.pose.transforms_clear(), but sometimes it gives me errors However I cant use bpy.ops since it gives me the following error: RuntimeError: Operator bpy.ops.pose.transforms_clear.poll() failed, context is incorrect

So, is there an alternative way?


1 Answer 1


Set each pose bone basis matrix to identity

Note: assuming there is no animation involved

With an armature object active and selected

>>> rig = C.object 

>>> rig

Clearing all pose transforms is the equivalent of setting the pose bone matrix basis to identity

>>> for pb in rig.pose.bones:
...     pb.matrix_basis.identity()

Use context.selected_pose_bones to narrow selection to those selected. (to be more in line with operator function)

However, like the operator context issues, this is only available in pose mode, which is quite likely the reason for poll failed error for bpy.ops.pose... operators.

Test in console, showing selected pose bone list is None and operator doesn't poll in OBJECT mode

>>> C.mode

>>> C.selected_pose_bones
>>> C.selected_pose_bones is None

>>> bpy.ops.pose.transforms_clear.poll()

>>> bpy.ops.object.mode_set()

But if switch to POSE mode (Side note: left in hander messages from running script here FWIW changing mode updates the depsgraph)

>>> bpy.ops.object.mode_set(mode='POSE')
1 : depsgraph_update_pre
1 : depsgraph_update_post

>>> C.mode

>>> C.selected_pose_bones

>>> bpy.ops.pose.transforms_clear.poll()

Set armatures pose_postion enum.

To switch into REST mode, The switch is in the UI in the DATA properties panel

, meaning its a property of the data part, (the edit bones)

>>> rig.data

It's in rest pose

>>> rig.data.pose_position

Change to pose position

>>> rig.data.pose_position = 'POSE'
  • 1
    $\begingroup$ Such a great answer. Thanks! $\endgroup$
    – Manveru
    Jul 8, 2021 at 11:31

You must log in to answer this question.

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