Python: list to sequence of strings


#1

Is there any way to do this?

I have a list with weight info and want to load it with just one command per point with setAttr. I’ve just found that using setAttr to set weights for all joints at the same time in one point is incredible fast. ( like 5+ times faster)

Let’s say I have this:

weightData = [0.0, 0.5, 0.5]

and I want to execute:

cmds.setAttr( ‘skinCluster.weightList[0].weights[0:100]’, 0.0, 0.5, 0.5 )

The problem is the weightData is a list, not a sequence of strings so setAttr doesn’t recognize it.

I ended up doing it with a long string and calling it with mel.eval, like this:

for i in range(len(points)):
            commText = '"'+ '%s.weightList[%s].weights[%s]' % (skinCl, i, '0:' + str(len(joints)-1) )+'" '  + ' '.join(map(str, weightData[i])) 
            mel.eval("setAttr " + commText)


It works fine, but I was wondering if I could write it entirely in Python.

Thanks


#2

Same idea with *args **kwargs. Quick example:

distance = [1, 2, 3]
cmds.move(*distance, r=1)

Works with dictionary too.

dimension = dict(
w = 5,
h = 5,
d = 2
)
cmds.polyCube(**dimension)


#3

Thanks!

It worked! gotta get rid of that mel.eval now!
but I’m sure I tried that before… I must have messed up some other part of the code that time.