PDA

View Full Version : maya MFnCompound attribute


mayaUser2011
01-15-2011, 04:51 AM
I am trying to create an attribute which is an array of array, and the number of elements are set at runtime. What I'm trying to store is an array of vertices, and at each index are multiple lists of angles, corresponding to the shapes affecting it.

I have set it up as : (I don't know if i'm missing something here)

jointAngles = tAttr.create("joints", "jts", MFnData::kDoubleArray);
tAttr.setStorable(true);
tAttr.setConnectable(true);
tAttr.setReadable(true);
tAttr.setWritable(true);
tAttr.setHidden(false);
cAttr.setArray(true);
tAttr.setUsesArrayDataBuilder(true);

// this is the compound attribute
vertices= cAttr.create("vertices", "vts");
cAttr.addChild(jointAngles);
cAttr.setStorable(true);
cAttr.setConnectable(true);
cAttr.setReadable(true);
cAttr.setWritable(true);
cAttr.setHidden(false);
cAttr.setArray(true);
cAttr.setUsesArrayDataBuilder(true);
addAttribute(THISCLASS::vertices);

Now when I try to access the data and set it up,

MObject obj;
MFnDoubleArrayData arr;
obj = arr.create(myArray, &stat);
MPlug parent = P.elementByLogicalIndex(vertex_index, &stat);
// for every shape there will be a list of joint angles
MPlug child = parent.child(0,&stat);

child.setValue(obj);

This sets the first shape's angles, when i try to access child at 1,2,3 etc it crashes, because there is no child there. And everytime this runs(per shape), it overwrites the data, how do I add multiple shapes at the child level ? i.e. multiple joint arrays under the child joint....

any help is appreciated, thanks !

INVINCIBLE0918
01-18-2011, 03:58 PM
could you post you initialize() method and compute () method code here?

mayaUser2011
01-18-2011, 05:32 PM
I'm trying to set the values in another class - not in the compute or deform area.... that's why I'm using plugs to get the data instead of the data block - since it doesn't apply here.

I have an array of arrays at the first child of the parent plug. I can't seem to get to the second array. i.e.

MPlug P = node.findPlug("vertices");
MPlug Parent = P.elementByLogicalIndex(vertex_index, &stat);
MPlug Child = Parent.child(0,&stat);

// now this child, is an array of kDoubleArrays
MPlug shapeP = Child.elementByLogicalIndex(shapeIndex,&stat);

the above fails, how do I iterate over this array ? and then eventually set the values.

// (and eventually this should happen)
MObject array;
MFnDoubleArrayData A;
array = A.create(array, &stat);
shapeP.setValue(array);

INVINCIBLE0918
01-19-2011, 02:25 PM
MPlug P = node.findPlug("vertices");
MPlug Parent = P.elementByLogicalIndex(vertex_index, &stat);
int num = Parent.numChildren(); // to see parent has how many children
for(int i = 0 ;i < num ; i ++)
{
MPlug Child = Parent.child(i); // to iterate these children
}

whisperwing
02-04-2011, 01:36 AM
1. the compound attribute "vertices" has only one child, ie. "jointAngles", so only child[0] is a legal plug

2.
jointAngles = tAttr.create("joints", "jts", MFnData::kDoubleArray);
cAttr.setArray(true);
"jointAngles" by definition is an array of double array.

Is this really what you want ?

CGTalk Moderation
02-04-2011, 01:36 AM
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.