If it is a array data type like doubleArray or intArray, you can set the default array in the attribute initialization function. If it is a setArray(True) attribute, you can do it a couple ways.
You can: 1. Use MDGMessage::addNodeAddedCallback, and populate the array with the node creation callback. or 2. Have a boolean initialization function that starts as false. In your compute, if it is false, set your default values, then set it to true. On Mon, Apr 26, 2010 at 9:06 PM, Chad Dombrova <[email protected]> wrote: > On the next call to compute won't that overwrite whatever values the user > inputs for those elements? i was hoping to setup some defaults just on > creation. i could hack together something with a boolean variable that > tracks whether i've setup the defaults and check it on every call to > compute, but that just seems pretty heavy handed. > > -chad > > > On Apr 26, 2010, at 6:27 PM, <[email protected]> wrote: > > I had this in my compute function when I added default elements: > > thisNode = self.thisMObject() > wPlug = OpenMaya.MPlug( thisNode, weightListNode.aWeights ) > > #Write into aWeightList > for i in range(3): > wPlug.selectAncestorLogicalIndex( i, > weightListNode.aWeightsList ) > wHandle = wPlug.constructHandle(dataBlock) > arrayHandle = OpenMaya.MArrayDataHandle( wHandle ) > arrayBuilder = arrayHandle.builder() > for j in range( 5 ): > handle = arrayBuilder.addElement( j ) > value = i+j > handle.setFloat(value) > arrayHandle.set(arrayBuilder) > wPlug.setMDataHandle(wHandle) > wPlug.destructHandle(wHandle) > > > Don't have time to strip it down to its bare minimum or why I nested the > loops. > > Hope that gets you going, > -brian > www.meljunky.com > > -------- Original Message -------- > Subject: [Maya-Python] api: creating default array elements > From: Chad Dombrova <[email protected]> > Date: Mon, April 26, 2010 4:37 pm > To: Maya Python Group <[email protected]> > > hi, > i'm writing a custom node that has an input array attribute. when an > instance of this node is created i would like to populate the array with > several default values. within the context of an MPxNode where is the best > place to do this and how? calling getAttr myNode.myAttr[0] after creation > will add the element, but this seems pretty hacky to me and maya's nodes > don't resort to this. for example, the following code shows how a > fluidShape's incandescence has 3 elements after a createNode call: > > s = createNode('fluidShape') > print getAttr(s + '.incandescence', size=1) > > thanks, > chad > > > > > -- > http://groups.google.com/group/python_inside_maya > > > -- > http://groups.google.com/group/python_inside_maya > > > -- > http://groups.google.com/group/python_inside_maya > -- http://groups.google.com/group/python_inside_maya
