Clear an array attribute


#1

In my plugin I have an array attribute:

MFnNumericAttribute PhiAttr;
mPhiAttr = PhiAttr.create("Phi" ,"Phi", MFnNumericData::k2Double, std::numeric_limits<double>::infinity(), &stat);
CHECK_MSTATUS(PhiAttr.setArray(true));
CHECK_MSTATUS(addAttribute(mPhiAttr));
CHECK_MSTATUS(attributeAffects(mPhiAttr, mOutputFlagAttr));

which I populate like this

int numElements = complexVector.nRows();
MFnDependencyNode thisDagNode(thisMObject(), &stat);
MPlug arrayPlug = thisDagNode.findPlug(double2ArrayMayaAttribute, false, &stat);
for(int i = 0; i < numElements; i++)
{
    MPlug plugAtIndex = arrayPlug.elementByLogicalIndex(i, &stat);
    stat = plugAtIndex.child(0, &stat).setDouble(complexVector(i, 0)._Val[0]);
    stat = plugAtIndex.child(1, &stat).setDouble(complexVector(i, 0)._Val[1]);
}

How do I clear the array - delete all its elements? I tried the following, but it didn’t work

MFnDependencyNode node(this->thisMObject(), &stat);
MPlug arrayPlug = node.findPlug(mPhiAttr, false, &stat);
arrayPlug.setValue(MObject());


#2

Okay, when creating the attribute, need to set:

CHECK_MSTATUS(PhiAttr.setUsesArrayDataBuilder(true));