Python xfrom and setAttr error; 'no attribute getitem'?


#1

Greetings,
I’m working on a script which simply queries the position of the hip joint
and then moves a locator to that position.

For some reason I get an error when trying to set the locator position on line 4:

import maya.cmds as cmds
loc = cmds.spaceLocator(n='posLoc#')
pos = cmds.xform('hip', q=1, translation=1)
cmds.setAttr(loc + '.translate', pos[0][0], pos[0][1], pos[0][2], type='double3')

Thank you for the help.


#2

The result of xform is not a two dimensional array but a simple list. So pos[0][0] is invalid, it should be pos[0].


#3

Thanks for the reply.
This way worked

cmds.setAttr(loc + ‘.translate’, pos[0], pos[1], pos[2], type=‘double3’)

Thank you