1

I'm relatively new to node writing and Maya's Python 2.0 API and am creating a custom node to do some computation using a pre-determined number of input points. For our purposes, we'll say 7 points.

I've successfully added the Compound Array attribute to my node using the following code in my Node Class's initialize method:

    cAttr = OpenMaya.MFnCompoundAttribute()
    node.test = cAttr.create('test','t')

    xv = OpenMaya.MFnUnitAttribute()
    node.testX = xv.create('testX','tx',OpenMaya.MFnUnitAttribute.kDistance)
    xv.storable = True
    xv.writable = True
    cAttr.addChild(node.testX)

    xv = OpenMaya.MFnUnitAttribute()
    node.testY = xv.create('testY','ty',OpenMaya.MFnUnitAttribute.kDistance)
    xv.storable = True
    xv.writable = True
    cAttr.addChild(node.testY)

    xv = OpenMaya.MFnUnitAttribute()
    node.testZ = xv.create('testZ','tz',OpenMaya.MFnUnitAttribute.kDistance)
    xv.storable = True
    xv.writable = True
    cAttr.addChild(node.testZ)

    cAttr.array = True 

    node.addAttribute(node.test)

Now that I have this, how can I specify that I want the node.test (cAttr) array to have 7 elements?

Thanks so much!

stowaway
  • 77
  • 9

1 Answers1

0

If you're asking to have a default size, or a fixed size for the Array at the time you define the compound, there is no solution.

All you can do is to setup the attribute array for each instance as soon as they are created. To do this, you need to implement the postConstructor() method. That method is called by the Maya core right after the custom python object instance becomes a valid Maya node.

postConstructor() -> self

Internally maya creates two objects when a user defined node is created, the internal MObject and the user derived object. The association between the these two objects is not made until after the MPxNode constructor is called. This implies that no MPxNode member function can be called from the MPxNode constructor. The postConstructor will get called immediately after the constructor when it is safe to call any MPxNode member function.

cyrille
  • 2,616
  • 1
  • 10
  • 18