1
$\begingroup$

I found a way to point to bones in an armature

import bpy

armature = bpy.data.armatures["Armature"]
for bone in armature.bones:
    print(bone.name)

Here I want to check for names of bones and if those name match then I am looking to remove all the animation from that bone including all Scale , Location and Quaternion Rotation.

Thanks in Advance

$\endgroup$
3
  • $\begingroup$ As in same result as using `bpy.ops.anim.keyframe_clear_v3d() in pose mode with selected pose bones? $\endgroup$
    – batFINGER
    Commented May 11, 2017 at 15:40
  • $\begingroup$ Actually I am looking for a way to remove animation from body parts of character programmatically like 'limbs' and 'torso' , all this be done just by running the script in the object mode is there a way to point to dope sheet summary ie "W Quaternion Rotation (Neck1)" and also a way to remove them. $\endgroup$ Commented May 11, 2017 at 16:16
  • $\begingroup$ I found keyframe_delete(data_path, index=-1, frame=bpy.context.scene.frame_current, group="") but I am not sure how to use it $\endgroup$ Commented May 11, 2017 at 17:58

1 Answer 1

1
$\begingroup$

As batFINGER suggested in his comment. This can be done using bpy.ops.anim.keyframe_clear_v3d(). To do this in python you need to select the bone first then apply the operation. Below is a script to delete animation of a specific bone, in this example, a bone named 'Bone' will have its animation deleted:

import bpy

arm = bpy.data.objects['Armature']
bpy.ops.object.mode_set(mode='POSE')
bpy.ops.object.select_all(action='DESELECT')
arm.select = True
bpy.context.scene.objects.active = arm

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

bpy.ops.pose.select_all(action='DESELECT')

for pb in arm.pose.bones:
    if pb.name == 'Bone':
        arm.data.bones[pb.name].select = True
        bpy.ops.anim.keyframe_clear_v3d()
bpy.ops.object.mode_set(mode='OBJECT')
$\endgroup$
2
  • $\begingroup$ here I have to select the armature , you know a way by which the armature will get auto selected. Thanks in advance $\endgroup$ Commented May 12, 2017 at 15:11
  • $\begingroup$ @ShubhamSharma Answer updated, please mark and accept the answer if it solved your problem. $\endgroup$
    – Tak
    Commented May 12, 2017 at 18:09

You must log in to answer this question.

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