Reputation: 369
list = cmds.ls(sl = True)
How to get or set Attr e.g translateY
for objects in list
.
Upvotes: 1
Views: 9131
Reputation: 492
If you use pymel it's a lot simpler...
sel = selected()
for i in sel:
print i.ty.get()
i.ty.set(i.ty.get() + 1)
Upvotes: 1
Reputation: 3178
Unless there is a Maya specific issue that I don't know about, there are a couple of ways to do this in Python:
for myObject in myList:
# directly getting and setting attribute
myObject.translateY = 30.0 # set
a = myObject.translateY # get
# alternatively, via setattr and getattr built-in functions.
setattr(myObject, "translateY", 40.0)
# getter which Raises exception if myObject has no "translateY" attr:
a = getattr(myObject, "translateY")
# getter which supplies defaultVal if myObject has no "translateY" attr
a = getattr(myObject, "translateY", defaultVal)
As an aside, it is bad form to call your variable "list", as this name will shadow Python's built-in list function. Better to use something like "myList" instead.
Upvotes: 2