How to postpone MPxNode::compute(). Multiple connections

I have a custom node that takes multiple meshes stored in one array attribute.
Meshes are added trough the for loop in python.
The problem is that compute() function is called each time when new mesh is added, which is absolutely redundant operation. I am interesting in computation only when all meshes have been added. Is there a way to call compute() only when for loop ends ?

for x in range(10):
    cmds.connectAttr("pSphereShape1.outMesh", ("testNode1.inMeshe[%i]" % (x)))
MStatus testNode::initialize()
{
	MStatus stat;
	MFnTypedAttribute	typedAttr;

	mInputMeshe = typedAttr.create("inMeshe", "inM", MFnMeshData::kMesh, &stat);
	typedAttr.setArray(true);
	typedAttr.setWritable(true);
	typedAttr.setHidden(true);
	addAttribute(mInputMeshe);
	MCHECKERROR(stat, "mInputMeshe error");

	return(MS::kSuccess);
}

There are several options for that, but it’s depends how is your compute methods works. If input and ouput mesh attributes are binded together you can check: if ouput is connected - do compute(). That means you have to disconnect output connection before populating inputs.


import maya.OpenMaya as om
import maya.OpenMayaMPx as ompx


class ArrayNode(ompx.MPxNode):
    name = 'ArrayNode'
    nid = om.MTypeId(0x87023)
    inputs = om.MObject()
    output = om.MObject()

    @staticmethod
    def init():
        tattr = om.MFnTypedAttribute()

        ArrayNode.inputs = tattr.create('inputs', 'inps', om.MFnData.kMesh)
        tattr.setArray(True)

        ArrayNode.output = tattr.create('output', 'out', om.MFnData.kMesh)

        ArrayNode.addAttribute(ArrayNode.inputs)
        ArrayNode.addAttribute(ArrayNode.output)

        ArrayNode.attributeAffects(ArrayNode.inputs, ArrayNode.output)

    def __init__(self):
        ompx.MPxNode.__init__(self)

    def compute(self, plug, data):
        if plug == ArrayNode.output:
            print 'ON_COMPUTE'


def initializePlugin(mobject):
    def reg_node(node):
        try:
            mplugin.registerNode(node.name, node.nid, lambda: ompx.asMPxPtr(node()), node.init)
        except:
            print 'Registration failed for <%s> node.' % node.name

    mplugin = ompx.MFnPlugin(mobject, 'foo', '1.0', 'Any')

    # register node
    reg_node(ArrayNode)


def uninitializePlugin(mobject):
    def dereg_node(node):
        try:
            mplugin.deregisterNode(node.name)
        except:
            print 'Deregistration failed for <%s> command.' % node.name

    mplugin = ompx.MFnPlugin(mobject)

    # unregister command
    dereg_node(ArrayNode)