Select constraining object
This is a tiny snippet I threw together today to speed up selecting the object that was controlling my selected object. In this case the object that was being controlled was a curve, but the constraining object (controlling the curve) was an invisible transform node, so instead of going through the hypergraph I wrote this:
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
Note: this allows you to select multiple constrained objects and this will try and find the driving objects, this does not handle multiple constraints or anything fancy like that. Enjoy