On the great website xyz2.net there is the entry on How do I find the Shape node of a Transform? Or the Transform of a Shape node? But what if you want the Transforms of a list of Shape nodes?
proc string[] getTransform(string $shape[]) {
string $transform[];
for ($node in $shape) {
if ( "transform" != `nodeType $node` ) {
// If given node is already a transform, just pass on through
string $parents[] = `listRelatives -fullPath -parent $node`;
appendStringArray($transform, $parents, size($parents));
}
}
return $transform;
}
def getTransforms(shapeList, fullPath=False):
transforms = []
for node in shapeList:
if 'transform' != cmds.nodeType( node ):
parent = cmds.listRelatives( node, fullPath=fullPath, parent=True )
transforms.append( parent[0] )
return transforms