Hi,
There are several error in the sample,
1.Accessing compounds
Please get compound first then accessing to it's children with child command like below
MDataHandle compound = data.outputValue(nodeACompoundAttr);
MArrayDataHandle adh = data.outputArrayValue(nodeAIntArrayAttr);
MArrayDataBuilder adb = adh.builder();
unsigned int size = 10; // size of my array
while (adb.elementCount() > size) { adb.removeElement(adb.elementCount() - 1); }
while (adb.elementCount() < size) { adb.addLast(); }
adh.set(adb);
for (unsigned int i = 0; i < size; i++) {
adh.jumpToArrayElement(i);
adh.outputValue().setInt(i);
}
2. Not cleaning the output plug after compute
Please clean the dirtied plug after compute, the dirty will be broadcast one once if you don't clean it.
After you've posted code, it came to my mind that setDependentsDirty might not be required after EM was introduced to Maya, so you should be able to remove them right now.
The fixed code is attached below
#include <maya/MPxNode.h>
#include <maya/MFnCompoundAttribute.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnTypedAttribute.h>
#include <maya/MArrayDataBuilder.h>
#include <maya/MPlugArray.h>
#include <maya/MFnMesh.h>
#include <maya/MPointArray.h>
#include <maya/MFnPlugin.h>
#include <maya/MGlobal.h>
MObject nodeACompoundAttr, nodeAIntArrayAttr, nodeARecomputeAttr;
MObject nodeBCompoundAttr, nodeBIntArrayAttr, nodeBMeshAttr;
class nodeA : public MPxNode {
public:
MStatus compute(const MPlug& plug, MDataBlock& data) {
MGlobal::displayInfo(plug.name());
MDataHandle compound = data.outputValue(nodeACompoundAttr);
MArrayDataHandle adh = data.outputArrayValue(nodeAIntArrayAttr);
MArrayDataBuilder adb = adh.builder();
unsigned int size = 10; // size of my array
while (adb.elementCount() > size) { adb.removeElement(adb.elementCount() - 1); }
while (adb.elementCount() < size) { adb.addLast(); }
adh.set(adb);
for (unsigned int i = 0; i < size; i++) {
adh.jumpToArrayElement(i);
adh.outputValue().setInt(i);
}
adh.setAllClean();
compound.setClean();
return MStatus::kSuccess;
};
static void* creator() { return new nodeA(); };
static MStatus initialize() {
MFnCompoundAttribute cAttr;
MFnNumericAttribute nAttr;
nodeACompoundAttr = cAttr.create("compound", "c");
nodeAIntArrayAttr = nAttr.create("intarray", "ia", MFnNumericData::kInt, 0);
nAttr.setArray(true);
nAttr.setUsesArrayDataBuilder(true);
cAttr.addChild(nodeAIntArrayAttr);
cAttr.setHidden(true);
cAttr.setReadable(true);
cAttr.setWritable(true);
cAttr.setStorable(true);
nodeARecomputeAttr = nAttr.create("recompute", "r", MFnNumericData::kBoolean, 0);
addAttribute(nodeACompoundAttr);
addAttribute(nodeARecomputeAttr);
attributeAffects(nodeARecomputeAttr, nodeACompoundAttr);
attributeAffects(nodeARecomputeAttr, nodeBIntArrayAttr);
return MStatus::kSuccess;
};
static MTypeId id;
};
class nodeB : public MPxNode {
public:
MStatus compute(const MPlug& plug, MDataBlock& data) {
MDataHandle compoundValue = data.inputValue(nodeBCompoundAttr);
MArrayDataHandle adh = compoundValue.child(nodeBIntArrayAttr);
adh.jumpToElement(0);
for (unsigned int i = 0; i < adh.elementCount(); i++){
adh.jumpToElement(i);
}
auto handle = data.outputValue(nodeBMeshAttr);
MFnMesh meshFn;
MPointArray pointArray;
MIntArray polygonCounts;
MIntArray polygonConnects;
MObject mesh = meshFn.create(0, 0, pointArray, polygonCounts, polygonConnects);
handle.set(mesh);
handle.setClean();
return MStatus::kSuccess;
};
static void* creator() { return new nodeB(); };
static MStatus initialize() {
MFnCompoundAttribute cAttr;
MFnNumericAttribute nAttr;
MFnTypedAttribute tAttr;
nodeBCompoundAttr = cAttr.create("compound", "c");
nodeBIntArrayAttr = nAttr.create("intarray", "ia", MFnNumericData::kInt, 0);
nAttr.setArray(true);
nAttr.setUsesArrayDataBuilder(true);
cAttr.addChild(nodeBIntArrayAttr);
nodeBMeshAttr = tAttr.create("mesh", "m", MFnData::kMesh);
addAttribute(nodeBCompoundAttr);
addAttribute(nodeBMeshAttr);
attributeAffects(nodeBCompoundAttr, nodeBMeshAttr);
return MStatus::kSuccess;
};
static MTypeId id;
};
MTypeId nodeA::id(0x80028);
MTypeId nodeB::id(0x80029);
MStatus initializePlugin(MObject obj)
{
MStatus status;
MFnPlugin plugin(obj, PLUGIN_COMPANY, "6.0", "Any");
status = plugin.registerNode("nodeA", nodeA::id, nodeA::creator,
nodeA::initialize);
status = plugin.registerNode("nodeB", nodeB::id, nodeB::creator,
nodeB::initialize);
if (!status) {
status.perror("registerNode");
return(status);
}
return(status);
}
MStatus uninitializePlugin(MObject obj)
{
MStatus status;
MFnPlugin plugin(obj);
status = plugin.deregisterNode(nodeA::id);
status = plugin.deregisterNode(nodeB::id);
if (!status) {
status.perror("deregisterNode");
return(status);
}
return(status);
}
Yours,
Li