In Maya C++ API, how to limit max value of an attribute of MPxNode to half of another attribute value?

53 Views Asked by At

I'm developing a custom mpxnode that has 3 attributes (length, width, fillet) and one output. I want fillet attribute 'maxValue' to be the half of min(length, width) but can't get it to work.

For example:

in this image

maxValue of fillet attribute should be '1.5'

I tried this codes in compute method of MPxNode:

double limit = std::min(length, width) / 2;
MFnNumericAttribute filletAttr(Fillet);
filletAttr.setMax(limit);
MGlobal::executeCommandOnIdle("AEbuildControls;");

but the problem is it changes maxValue of fillet attribute in all instances of this MPxNode.

Can anyone help?

1

There are 1 best solutions below

0
On

Unfortunately, there's no way to set the maximum value of an attribute "per instance". The maximum value of the attribute's widget could be updated when the node is replaced. Ex:

global proc AEMyNodeTemplate ( string $nodeName )
{
    //... add controls to the Attribute Editor
    editorTemplate -callCustom "AEMyAttributeNew"
                               "AEMyAttributeReplace"
                               "myAttribute";
    //...
}

global proc int AEMyAttributeNew(string $myAttribute)
{
    // Create the layout and widgets..
    //...
    columnLayout myLayout;
    //...
}

global proc int AEMyAttributeReplace(string $myAttribute)
{
    string $nodeName[];
    tokenize ($fileAttribute, ".", $nodeName);

    // get the attribute widget
    setParent myLayout;
    string $children[] = `columnLayout -query -childArray myLayout`;
    // Find $myAttribute widget
    string $myWidget = ;//TODO

    string $lengthAttr = $nodeName + "." + "length";
    float $length = getAttr $lengthAttr;
    // ... get width value
    float $maxValue = min $length $width
    attrFieldSliderGrp $myWidget -e fieldMaxValue $maxValue;
}