Unpacking in python and doubleArray attrs

Hello,

Having trouble with doubleArrays.

I can set a string array easily like this:

import maya.cmds as cmds
 
ball = cmds.sphere()[0]
names = ["a", "b", "c"]
cmds.addAttr(ball, ln = "myStrings", dt= "stringArray")
cmds.setAttr(ball+'.myStrings', len(names),      type = "stringArray", *names)
cmds.getAttr(ball+".myStrings")
# Result: [u'a', u'b', u'c'] #

But similar code using a doubleArray gives an error:

numbers = [1, 2, 3]
cmds.addAttr(ball, ln = "myNums", dt= "doubleArray")
cmds.setAttr(ball+'.myNums', len(numbers),      type = "doubleArray", *numbers)
cmds.getAttr(ball+".myNums")
# RuntimeError: setAttr: Too much data was provided. The last 1 elements were not used. #

Any ideas why doubleArrays are n't the same as stringArrays?

Answering my own question :slight_smile:

The difference is the syntax of the setAttr command:

cmds.setAttr('node.stringArrayAttr',3,"a","b","c",type='stringArray')
cmds.setAttr( "node.doubleArrayAttr", (2, 3.14159, 2.782,), type="doubleArray")

The unpacking is needed in the string array as the values needed are a "bare" list.
So something like this works just fine:

numbers = [1, 2, 3]
cmds.addAttr(ball, ln = "myNums", dt= "doubleArray")
cmds.setAttr(ball+'.myNums', (numbers),      type = "doubleArray")
cmds.getAttr(ball+".myNums")
# Result: [1.0, 2.0, 3.0] #