for craig
import pymel.core as pm
"""
To use:
Select a control on the source and then a control on the destination
Run the copy command
Select controls of the source to be copied
Run the paste command
COPY COMMAND (select a control on the source, then destination):
import craig_copy_paste as ccp
reload(ccp)
craig_ccp = ccp.CraigCopyPaste()
PASTE (with source controls ONLY selected):
craig_ccp.copy_paste()
"""
class CraigCopyPaste:
def __init__(self):
self.get_source_destination()
def control_list(self):
selection = pm.selected()
self.controls = []
for s in selection:
self.controls.append(s.name().split(':')[-1])
print self.controls
def get_source_destination(self):
selection = pm.selected()
if len(selection) == 2:
self.namespace_a = pm.selected()[0].namespace()
self.namespace_b = pm.selected()[1].namespace()
else:
pm.warning('Select 1 control on the source and 1 on the destination')
def copy_paste(self):
if self.namespace_a and self.namespace_b:
self.control_list()
for ctrl in self.controls:
source = '{}:{}'.format(self.namespace_a, ctrl)
destination = '{}:{}'.format(self.namespace_b, ctrl)
try:
pm.copyKey(source)
pm.setKeyframe(destination)
pm.pasteKey(destination, option='replaceCompletely')
except RuntimeError:
print 'no keys on {}, skipping'.format(source)
else:
pm.warning('No source/destination established to copy/paste')