Blog

setAttr() quirks, Maya, Python

Posted by:

setAttr()

I was setting an attribute like this:

cmds.setAttr(newIkHandle[0].visibility, 0)

and I got this as an error:

‘unicode’ object has no attribute ‘visibility’

My first attempt at a fix was to format the unicode object, thinking that the argument needed a string:

cmds.setAttr(newIkHandle[0].encode(‘utf8’).visibility, 0)

The error message I received was:

‘str’ object has no attribute ‘visibility’

That tells me that you could use the explicit string of the object’s name, but not a variable of that object’s string.  So it’s not looking for the string, it’s looking for the object.

It turns out that maya expects that you will break the attribute out from the object:

cmds.setAttr(newIkHandle[0] + ‘.visibility’, 0)

This seems really weird to me because the unicode error message clearly recognizes the object that is being effected and it also clearly recognizes that .visibility is the attribute being set.  But for whatever reason it doesn’t find the attribute unless that attribute broken out from the object with the “+” sign.

0
  Related Posts
  • No related posts found.

You must be logged in to post a comment.