Skip to content

Instantly share code, notes, and snippets.

@wmoten
Last active December 3, 2023 06:22
Show Gist options
  • Save wmoten/e76ee3b807b1d79ba4ba94b2a4036d79 to your computer and use it in GitHub Desktop.
Save wmoten/e76ee3b807b1d79ba4ba94b2a4036d79 to your computer and use it in GitHub Desktop.
Getting Maya Proxy Attributes
from maya import cmds, OpenMaya
from pprint import pprint
import os
def _getProxyAttributeCommands(cmdsnode):
#Takes a string of a maya object, like 'pshere1'
#checks for proxy attributes
#returns mel command to make that proxy attribute
proxyAttrCmds = []
selectionList = OpenMaya.MSelectionList()
try:
selectionList.add(cmdsnode)
except:
return None
mobj = OpenMaya.MObject()
selectionList.getDependNode(0,mobj)
dep = OpenMaya.MFnDependencyNode(mobj)
for i in range(dep.attributeCount()):
attr = OpenMaya.MFnAttribute(dep.attribute(i))
if attr.isProxyAttribute():
#we have full access to MFnAttribute here
#example = attr.getAddAttrCmd(True)
proxyAttrCmds.append(dep.name() + '.' + attr.name())
return proxyAttrCmds
def repairProxyAttribute(rigpath, animpath, searchname=""):
cmds.file(rigpath, r=True)
if not searchname:
searchname = "_controllers_grp" #change this to be what you're looking for, or set to ""
controlGrps = [i for i in cmds.ls(type="objectSet", dag=True) if searchName in i]
proxyAttributes = {}
for ctrl in controlGrps:
children = cmds.listRelatives(ctrl, ad=True, pa=True)
for child in children:
cmd = _getProxyAttributeCommands(child)
for c in cmd:
proxyAttributes[c] = {'inputs' : cmds.listConnections(cmd, scn=True, p=True, source=False, destination=True)}
proxyAttributes[c] = {'outputs' : cmds.listConnections(cmd, scn=True, p=True, source=True, destination=False)}
#get the proxies use cmds to see their connections
#store those values.
cmds.file(animpath, o=True)
_connectAttributes(proxyAttributes)
repairProxyAttribute('/path/to/rig.ma', '/path/to/anim.ma', "_controllers_grp" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment