Charlotte Crouzet
Charlotte Crouzet

Reputation: 3

How to put the getAttr of any selected object inside a textField?

I'm a bit new in scripting and french so exuse me if my explanations are not perfectly clear.

I'm trying to make a script in Maya to manage easily the keys value for animation.

So I created a window reproducing Maya's ChannelBox with another organisation. And now I'm trying to get the attribute values of a selected object inside the different textField (transX, Y, Z, rotX..).

Here is what I have for now :

transX_value = cmds.textField( w=100 , h=22 , tx= cmds.getAttr("%s.translateX" %selected) )

But when I select my cube for tests and launch my script this error appears:

TypeError: Object [u'pCube1'].translateX is invalid

So I tried something like this to see if the problem is coming from my formulation:

transX_value = cmds.textField( w=100 , h=22 , tx= cmds.getAttr("pCube1.translateX") )

It worked and printed the good value inside the textField.

How can I call the attribute of any selected object? I just discovered the %s command, so I'm sure that I'm not using it right.

Upvotes: 0

Views: 538

Answers (1)

ababak
ababak

Reputation: 1803

That's a very common mistake. Your 'selected' variable holds a list, not a string. You should get the first list value instead, so just change your code like that:

transX_value = cmds.textField(w=100, h=22, tx=cmds.getAttr("%s.translateX" % selected[0]))

Upvotes: 2

Related Questions