how can i get translate values in maya python api?
Question: Actually i'am new to api and am trying to get the translation values(x,y,z)
but the problem is i cant get when i specify only "translate" instead of
"translateX", "translateY", "translateZ" in every separate line. is there any
way to get what i actually want?

here's the code:

    
    
    import maya.OpenMaya as om
    
    selected = om.MSelectionList()
    om.MGlobal.getActiveSelectionList(selected)
    
    obj = om.MObject()
    selected.getDependNode(0,obj)
    
    print(om.MFnDependencyNode(obj).findPlug("translateX").asFloat())
    print(om.MFnDependencyNode(obj).findPlug("translateY").asFloat())
    print(om.MFnDependencyNode(obj).findPlug("translateZ").asFloat())
    

thank you...


Answer: The translate attribute is a compound attribute. In the Maya API, you have to
individually query each child attribute of a compound attribute in order to
retrieve the complete value of the compound attribute.

But the MEL getAttr() command can retrieve the value of the translate
attribute all at once. Since you are using Python, you can mix MEL commands
and calls to the Maya API together in the same script:

    
    
    import maya.OpenMaya as om
    import maya.cmds as cmds
    
    selected = om.MSelectionList()
    om.MGlobal.getActiveSelectionList(selected)
    
    obj = om.MObject()
    selected.getDependNode(0,obj)
    
    depNodeName = om.MFnDependencyNode(obj).name()
    
    print(cmds.getAttr(depNodeName + '.translate')[0])
    

