1
list = cmds.ls(sl = True)

如何获取或设置 Attr translateY,例如list.

4

2 回答 2

2

除非有我不知道的 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”之类的东西。

于 2013-07-06T07:09:23.037 回答
1

如果你使用pymel,它会简单得多......

sel = selected()

for i in sel:
    print i.ty.get()
    i.ty.set(i.ty.get() + 1)
于 2013-07-09T18:20:54.973 回答