Initializing something in compute and checking it later every time compute is called is just wrong. The whole purpose of the dependency graph is to maintain efficient [lazy] evaluation of the network. For that reason, I personally would not put such a check into compute. If the node is part of some larger system then I'd build this initialization into the system. For instance, we have a basic nodetype that we hang a lot of data off of. If the node is created with the standard 'createNode' then there is no unique data on that node. It is incumbent on the system to format the node upon creation so that the node has meaning to the system. We have an api that facilitates node creation and manipulation, such as connection management, querying, etc., that wraps all of the core maya calls, and does all of our specific handling. It's a data driven system that uses an xml file to describe the structure of the data that should appear on each of the nodes.We also register a number of callbacks for these nodes when they are created, as Chad Vernon mentions. If the node is not part of a larger system then you may not have the code infrastructure in place that wold allow you to do this sort of thing easily. I would still consider wrapping the creation call into a special purpose call designed to set this node up properly. I know initializing the attribute values in this way isn't perhaps as cool or tidy, but it will keep the dg running efficiently.
A couple of questions come to mind: Who is going to be creating this node? When will the node be created? On Mon, Apr 26, 2010 at 9:50 PM, <[email protected]> wrote: > I realize the plug-in I pulled it from didn't really do anything but print > out some results. Was created for testing purpose and I only made the > compute run once (Think I converted it from C++). Your right it would try to > create the plugs each time. I keep coming to the same conclusion of some > form of boolean or comparing the element count unless one the the methods in > the MPxNode can help. > > -brian > www.meljunky.com > > > -------- Original Message -------- > Subject: Re: [Maya-Python] api: creating default array elements > From: Chad Dombrova <[email protected]> > Date: Mon, April 26, 2010 9:06 pm > To: [email protected] > > 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 > -- http://groups.google.com/group/python_inside_maya
