Created
June 16, 2021 20:49
-
-
Save justinsbarrett/4cbac46a3d2cb9ff98a4631f1e2d1524 to your computer and use it in GitHub Desktop.
This attempts to reconnect any disconnected animCurve nodes found in a Maya scene. Written for Python 2.x. Adjust as needed for v3+
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 maya.cmds as mc | |
def findNodeAndAttribute(animCurve): | |
parts = animCurve.split("_") | |
for index in range(len(parts)): | |
node = "_".join(parts[:index + 1]) | |
attribute = "_".join(parts[index + 1:]) | |
# Look for the node | |
# If it exists, look for the attribute | |
if mc.objExists(node): | |
attributes = mc.listAttr(node) | |
# If the attribute exists, return both | |
if attribute in attributes: | |
return [node, attribute] | |
return ["", ""] | |
for curveNode in mc.ls(type="animCurve"): | |
# Find the node and attribute names | |
node, attribute = findNodeAndAttribute(curveNode) | |
if node == "": | |
print "Unable to find a matching node for curve:", curveNode | |
continue | |
source = curveNode + ".output" | |
destination = node + "." + attribute | |
# Reconnect the animCurve to its attribute | |
print "Connecting " + source + " to " + destination | |
try: | |
mc.connectAttr(source, destination) | |
except: | |
continue | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment