[amaya][python] selecting the transform of a shape

Problem: I have a bunch of OBJs to process in maya.
the OBJ meshes are misnamed, so I need to automate the renaming, among other stuff.

after I import the obj, I want to select its transform.
cmds.ls(typ=‘transform’) will grab the cameras as well as the mesh, so that won’t work.
The only way I can think of to isolate the mesh is cmds.ls(typ=‘mesh’)
but this grabs the shape node, not the transform.
I have indirect approach that replaces ‘Shape’ in the mesh node string to generate the transform node name…but this feels hacky and possibly unreliable.

import maya.cmds as cmds
itemShape=(cmds.ls(typ='mesh')[0])
cmds.select(itemShape.replace('Shape',''))#remove 'Shape' to yield transform name
selection=cmds.ls(sl=True)
itemMesh=selection[0]
print (itemMesh)
print(cmds.nodeType(itemMesh))

a second also indirect approach is to select only visible transforms with
cmds.ls(v=True ,typ=‘transform’) but it’s still…indirect.

Is there away to explicitly list the transforms of shapes?

Once you find the shape node, you can simply find it’s parent to get the transform.

shapeList = cmds.ls(typ='mesh')
transformList = cmds.listRelatives(shapeList, parent=True, fullPath=True)
print transformList

you could use the listRelatives to get the parents of objects with a ‘transform’ type filter.

mc.listRelatives(mc.ls(type='mesh'),type='transform',p=True)

ah, should’ve refreshed page… RFlannery beat me to it…