import bpy
# Make sure you are in Pose mode
bpy.ops.object.mode_set(mode='POSE')
# Specify the axes you want to reset: 'X', 'Y', or 'Z'
selected_axes = ['X', 'Y'] # Change this list to include the desired axes, e.g., ['X', 'Y', 'Z']
# Iterate through all bones in the armature
for bone in bpy.context.object.pose.bones:
if bone.rotation_mode == 'QUATERNION':
# If the bone uses quaternions for rotation
quat = bone.rotation_quaternion
if 'X' in selected_axes:
quat.x = 0.0
if 'Y' in selected_axes:
quat.y = 0.0
if 'Z' in selected_axes:
quat.z = 0.0
quat.normalize()
elif bone.rotation_mode == 'AXIS_ANGLE':
# If the bone uses axis-angle for rotation
axis_angle = bone.rotation_axis_angle
if 'X' in selected_axes:
axis_angle[1] = 0.0
if 'Y' in selected_axes:
axis_angle[2] = 0.0
if 'Z' in selected_axes:
axis_angle[3] = 0.0
else:
# If the bone uses Euler angles for rotation
euler = bone.rotation_euler
if 'X' in selected_axes:
euler.x = 0.0
if 'Y' in selected_axes:
euler.y = 0.0
if 'Z' in selected_axes:
euler.z = 0.0
# Update the scene
bpy.context.view_layer.update()
```