Created
September 23, 2017 23:06
-
-
Save splinecraft/afdb7ef08a5edab667cd25b9494f1cfd to your computer and use it in GitHub Desktop.
for craig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment