randoms = [rand.uniform(-1,1)for items in range(10)]
x= 0
for i in List:
cm.setKeyframe(at = "%s.cv[x].xValue"%i , t=5, v=rand.choice(randoms))
x+=1
我想使用这部分代码,但 Maya 不能接受这个 [x]。有人告诉我你应该这样做:
for i in List:
x = 0
cvAttrX = i+".cv["+str(x)+"].xValue"
cm.setKeyframe(at = cvAttrX , t=5, v=rand.choice(randoms))
x+=1
但我收到了这个错误:
# Error: line 1: can only concatenate list (not "str") to list
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# File "<maya console>", line 7, in randList
# TypeError: can only concatenate list (not "str") to list #
如果有人解决这个问题,请向我深入解释。我想很好地学习这个,也请修复这个例子:
randoms = [rand.uniform(cm.floatField(Ceil, q = True , v = True),0.5)for i in range(30)]
for objects in myList:
cm.xform('%s.cv[0]'%objects , r = True , t = [(rand.choice(randoms)),(rand.choice(randoms)),(rand.choice(randoms))])
cm.xform('%s.cv[1]'%objects , r = True , t = [(rand.choice(randoms)),(rand.choice(randoms)),(rand.choice(randoms))])
cm.xform('%s.cv[2]'%objects , r = True , t = [(rand.choice(randoms)),(rand.choice(randoms)),(rand.choice(randoms))])
cm.xform('%s.cv[3]'%objects , r = True , t = [(rand.choice(randoms)),(rand.choice(randoms)),(rand.choice(randoms))])
cm.xform('%s.cv[4]'%objects , r = True , t = [(rand.choice(randoms)),(rand.choice(randoms)),(rand.choice(randoms))])
cm.xform('%s.cv[5]'%objects , r = True , t = [(rand.choice(randoms)),(rand.choice(randoms)),(rand.choice(randoms))])
cm.xform('%s.cv[6]'%objects , r = True , t = [(rand.choice(randoms)),(rand.choice(randoms)),(rand.choice(randoms))])
cm.xform('%s.cv[7]'%objects , r = True , t = [(rand.choice(randoms)),(rand.choice(randoms)),(rand.choice(randoms))])
cm.xform('%s.cv[8]'%objects , r = True , t = [(rand.choice(randoms)),(rand.choice(randoms)),(rand.choice(randoms))])
cm.xform('%s.cv[9]'%objects , r = True , t = [(rand.choice(randoms)),(rand.choice(randoms)),(rand.choice(randoms))])
cm.xform('%s.cv[10]'%objects , r = True , t = [(rand.choice(randoms)),(rand.choice(randoms)),(rand.choice(randoms))])
这是我脚本的一部分,如果我可以做增量,我不想为示例 100 次编写这一行,我可以为此制作 intField 并确定我需要多少
我想做这样的事情,但我不知道怎么做
import maya.cmds as cm
import random as rand
myList = cm.ls(sl =True)
cvList = []
randomList = []
def Lister():
for i in myList:
cvList.append(cm.ls('%s.cv[:]'%i , flatten = True))
return cvList
def randomize():
x = 0
randomList.append([rand.uniform(-1,1)for items in range(10)])
for i in cvList:
cm.setKeyframe(at = "%s.cv[x].xValue"%i , t=5, v=rand.choice(randoms))
x+=1