MEL: How do I find the Transforms of a list of Shape nodes?

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

Infinite loops? Naaah

Did it ever happen to you to feel stupid in front of your program stuck in an infinite loop?

We all now that feeling…

The documentation of Mari’s API and the Python Console are really bad to work with, but at least there is one great thing about Mari: you can very easily stop your scripts if they are stuck.

Simply hit Ctrl+C in the terminal Mari has been launched from and… that’s it, your script stopped and you can continue to work normally. It’s quite useful especially since Mari takes a lot of time to simply print some strings.