Sunday, November 04, 2012

Select constrained to object


Ever worked in a complex scene created by someone else with all kinds of constraints and nested constrained objects? Nightmare finding what object is constrained to what? This python script will select the object that your object is constrained to. Sweet. Map to a button - done.


import maya.cmds as mc
selection = mc.ls(sl=1)
toSelect = []
for item in selection:
   constraint = mc.listConnections( item+'.parentInverseMatrix[0]', d=1, s=0,type='constraint')
   if constraint:
      constraint = constraint[0]
      src = mc.listConnections(constraint+'.target[0].targetParentMatrix', d=0, s=1)
      if src:
         toSelect.extend(src)
try:
   mc.select(toSelect)
except:
   pass