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

Reply via email to