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
bpy.data.objects['Armature']
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
'OBJECT'
>>> C.selected_pose_bones
>>> C.selected_pose_bones is None
True
>>> bpy.ops.pose.transforms_clear.poll()
False
>>> bpy.ops.object.mode_set()
{'FINISHED'}
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
{'FINISHED'}
>>> C.mode
'POSE'
>>> C.selected_pose_bones
[bpy.data.objects['Armature'].pose.bones["Bone"]]
>>> bpy.ops.pose.transforms_clear.poll()
True
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
bpy.data.armatures['Armature']
It's in rest pose
>>> rig.data.pose_position
'REST'
Change to pose position
>>> rig.data.pose_position = 'POSE'
>>>