Skip to content

Instantly share code, notes, and snippets.

@tokejepsen
Created January 8, 2016 17:09
Show Gist options
  • Save tokejepsen/3b00d87a37ae8bd0c540 to your computer and use it in GitHub Desktop.
Save tokejepsen/3b00d87a37ae8bd0c540 to your computer and use it in GitHub Desktop.
mixamo rig reference replacement
import os
import pymel.core
def replaceReference():
basicFilter = "*.mb"
f = pymel.core.fileDialog2(fileFilter=basicFilter, dialogStyle=1, fileMode=1)
if not f:
return
f = f[0]
attrs = ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'FK_IK']
for node in pymel.core.ls(selection=True):
ns = node.name().split(':')[0]
new_nodes = pymel.core.createReference(f, returnNewNodes=True, namespace=os.path.basename(f))
for src in pymel.core.ls(ns + ':*'):
for dst in new_nodes:
if src.name().split(':')[-1] == dst.name().split(':')[-1]:
for attr in attrs:
try:
count = pymel.core.keyframe(src, attribute=attr, query=True, keyframeCount=True)
if count:
keys = pymel.core.keyframe(src.name() + '.' + attr, index=(0, count - 1), query=True)
pymel.core.copyKey(src.name(), time=(keys[0], keys[-1]), attribute=attr, option="curve")
pymel.core.pasteKey(dst.name(), attribute=attr)
else:
dst.attr(attr).set(src.attr(attr).get())
except:
pass
replaceReference()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment