PDA

View Full Version : Question regarding addAttr/ getAttr for "doubleArray"


margirbee
11-20-2012, 05:29 PM
Hi guys,

I need a help to sort out.
I did a test to add an attribute of type doubleArray, and then assign values to it.
But I got an unexpected result in MEL version, while got a correct one in python/ pymel
below are the MEL version

// MEL
createNode null -n "myNode";
addAttr -ln "value" -dt doubleArray;
setAttr "myNode.value" -type doubleArray 1.0 2.1 3.1;
print `getAttr myNode.value`;

// Result:
// Warning: Unrecognized node type 'null'; preserving node information during this session. //
// 2.1

The result output only 1 number instead of 3.
Later, I tried to change the 3rd line to setAttr "myNode.value" -type doubleArray 2.0 2.1 3.1;
and run the 4th line again, and the result turned to...

// Result:
// 2.1
// 3.1

As showed above, the 1st value I gave was always ignored for unknown reason, and the rest ones were correctly output as long as the 1st value is >= 2.0.


Lastly, I did same thing in python/ pymel, and it output as my expectation.
## python/ pymel
from pymel.core import *
import maya.cmds as mc
mc.createNode( 'null', n='myNode')
mc.addAttr( longName='value', dt='doubleArray' )
PyNode('myNode').value.set( [1.0, 1.1, 1.2] )
print PyNode('myNode').value.get()

// Result:
// [1.0, 1.1000000000000001, 1.2]

Could anyone do me a favor to explain what's going on with my 3 test? Thanks!


Margirbee

Nyro
11-20-2012, 05:55 PM
You should check out the syntax in the MEL documentation, particularly the examples written in the description of the setAttr command:

when setting attributes of type doubleArray, the first argument must be an integer defining how many elements the array will contain. It is then followed by the respective count of actual array-values you want to populate the attribute with.

Here's an example; I want to create an attribute to hold an array of three doubles:

addAttr -ln "threeDoubles -dt "doubleArray";

setAttr myNode.threeDoubles -type "doubleArray" 3 2.1 1.3 5.6;

CGTalk Moderation
11-20-2012, 05:55 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.