How would you delete all keyframes with a 0,0,0 location in Python?
I am cleaning mocap data and been deleting them manually in the graph editor, but it must be much faster to do it with a script. Thanks!
Is that 0,0,0 location of objects? Keyframes are actually 2D.
A screenshot would be nice!
Yes, it is the location of empties. Aha, so keys is probably what I mean
I will see if I manage to post a screenshot… Thank you for replying
Hi colorina,
Since this is mocap data then all the key frame frames are the same for each location / rotation in the import across all the bones or empties.
.
This being the case you can select the top object in the hierarchy loop thru its key-frame points, change to that frame and then delete the location keyframes if their vector length is less than some tolerance.
import bpy
from math import floor
context = bpy.context
scene = context.scene
mt = context.active_object
action = mt.animation_data.action
TOL = 0.00001 # Tolerance.
fcurve = action.fcurves[0]
frames = [f.co[0] for f in fcurve.keyframe_points] # frames used in bvh import.
for f in frames:
frame = floor(f)
subframe = f - frame
scene.frame_set(frame, subframe)
# could loop thru all mt objects or bones created from mocap import here.
if mt.location.length < TOL:
s = mt.keyframe_delete('location')
#print('location', s) # s is the success of operation
if mt.delta_location.length < TOL:
s = mt.keyframe_delete('delta_location')
#print('delta_loc', s)
PS included delta_location too as the default bvh importer uses this for location when importing as empties.
That seems to work Thank you so much batFINGER!
I found so many helpful answers from you when I am searching the internet, so thanks for that help too!