list = cmds.ls(sl = True)
如何获取或设置 Attr translateY
,例如list
.
除非有我不知道的 Maya 特定问题,否则在 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)
顺便说一句,调用变量“list”是一种不好的形式,因为这个名称会影响 Python 的内置列表函数。最好改用“myList”之类的东西。
如果你使用pymel,它会简单得多......
sel = selected()
for i in sel:
print i.ty.get()
i.ty.set(i.ty.get() + 1)