splinecraft
4/6/2017 - 12:09 AM

print the frame length and value between 2 selected keyframes on a single curve

print the frame length and value between 2 selected keyframes on a single curve

# Print the frame and value length of selected keys on a single curve    
import pymel.core as pm

curve = pm.findKeyframe(c=True)

if len(curve) == 1:     # only 1 curve selected
    l_keys = pm.keyframe(q=True, selected=True, tc=True)
    v_keys = pm.keyframe(q=True, selected=True, vc=True)
    
    if len(l_keys) > 1:   # at least 2 keys selected
        key_length = abs(l_keys[-1] - l_keys[0])
        key_value = abs(v_keys[-1] - v_keys[0])
        print ("len: {}, val: {:.3f}".format(key_length, key_value)),
    else:
        pm.warning('Need to select at least 2 keys'),
else:
    pm.warning('Select only 1 curve'),