Skip to content

Instantly share code, notes, and snippets.

@zewt
Created December 20, 2017 21:40
Show Gist options
  • Save zewt/b4829c63500de72682785dc40a9cb4c6 to your computer and use it in GitHub Desktop.
Save zewt/b4829c63500de72682785dc40a9cb4c6 to your computer and use it in GitHub Desktop.
Remap animation sources in Maya's time editor
import pymel.core as pm
def remap_clip(clip_name, new_anim_source):
clip_id = pm.timeEditorClip(clip_name, q=True, clipIdFromNodeName=True)
print 'Remapping clip:', clip_name
sources = pm.timeEditorClip(clip_id, q=True, remappedSourceAttrs=True)
source_indices, source_paths = sources[0::2], sources[1::2]
# targets = pm.timeEditorClip(clip_id, q=True, remappedTargetAttrs=True)
# target_indices, target_paths = targets[0::2], targets[1::2]
for source in source_paths:
if not source:
continue
# print source
pm.timeEditorClip(e=True, clipId=clip_id, remapSource=(source, ''))
clip_name = pm.timeEditorClip(clip_id, q=True, name=True)
pm.timeEditorClip(clip_name, e=True, clipId=clip_id, animSource=new_anim_source)
targets = pm.timeEditorClip(clip_id, q=True, remappedTargetAttrs=True)
target_indices, target_paths = targets[0::2], targets[1::2]
for path in target_paths:
pm.timeEditorClip(e=True, clipId=clip_id, remap=(path, ''))
def go():
selection = pm.ls(sl=True, type='timeEditorAnimSource')
if len(selection) < 1:
print 'Select a new and an old animation source'
return
new_anim_source = selection[0]
old_anim_source = selection[1]
connected_anim_clips = old_anim_source.attr('rosters').listConnections(s=False, d=True, type='timeEditorClip')
print 'Remapping: %s -> %s' % (old_anim_source, new_anim_source)
print 'Animation clips to remap: %i' % len(connected_anim_clips)
for clip_name in connected_anim_clips:
remap_clip(clip_name, new_anim_source)
go()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment