splinecraft
7/5/2017 - 1:57 AM

offset copy keys - copies curves down a selection of controls, based on selection order and offset value.

offset copy keys - copies curves down a selection of controls, based on selection order and offset value.

import pymel.core as pm
import maya.cmds as cmds

# to do - check for anim layers

offset = 4
selection = cmds.ls(sl=True, fl=True)

if len(selection) > 1:
    curves = pm.keyframe(selection[0], q=True, sl=True, name=True)
    
    if curves:
        curve_select = True
    else:
        curves = pm.listConnections(selection[0], type='animCurve')
        curve_select = False

print curves
print curve_select
start_frame = 1

for curve in curves:
    first = pm.keyframe(curve, q=True, tc=True)[0]
    if  first < start_frame:
        start_frame = first

offset_list = []
s = int(start_frame)

for i in range(s, (s + (offset*len(selection)+1)), offset):
    offset_list.append(i)

if curve_select:
    del offset_list[0]
    for ctrl, frame in zip(selection, offset_list):
        for curve in curves:
            attribute = curve.split('_')[-1]
            pm.copyKey(selection[0], at=attribute)
            pm.pasteKey(ctrl, option='replaceCompletely', at=attribute, time=(frame,))
else:        
    pm.copyKey(selection[0])
    del selection[0], offset_list[0]

    for ctrl, frame in zip(selection, offset_list):
        pm.pasteKey(ctrl, option='replaceCompletely', time=(frame,))