質問

list = cmds.ls(sl = True)

How to get or set Attr e.g translateY for objects in list.

役に立ちましたか?

解決 2

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)

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top