Feedback

What's your question?

By: Asked

Maya API: want to create a new input slot if the first(preceding) slot has been created.

Hi, i am writing a plugin which takes multiple inputs and based on a condition outputs one of those..!

I am stuck at creating the next input slot as the first one's connected

can someone point me in the right direction..????????

Thanks. Iceboxx

Add comment viewed 264 times Latest activity 11 months ago

or Cancel

2 answers

  • 1

manny [ Editor ]

Just query the value of the next slot. It gets automatically created.

NN comments
jagadish kumar
-

i am creating a MFnNumericAttribute, and i am only creating one attribute in my init function how do i query the next input..?

Pardon me i’m just learning to do mayaAPI

jagadish kumar
-

Do i have to create a compound attribute and then add my normal float attribute as a child, then to create a new child attribute i just need to query the next element in the array..?

or Cancel
  • 1

julian [ Admin ]

They are called multi attributes (many plugs), in order to distinguish them from array attributes (an array of values in one plug)

But just to confuse you, when you create a multi attribute in the initialize function you need to call setArray(true)

aBlender  = nAttr.create( "blender", "bl", MFnNumericData::kDouble);
nAttr.setKeyable(true);
nAttr.setArray(true);
addAttribute( aBlender );

That will allow you to make indexed plugs for the attribute:

myNode.blender[0] , myNode.blender[1] ... myNode.blender[n]

The attribute editor for that node should set up an "Add Item" button. Or you can just use setAttr or connectAttr in a script.

To get the data from those indexed plugs in your compute function, you have a couple of choices. It depends whether you want them all, or just the one that matches the index of an output attribute.

If you want them all:

MArrayDataHandle hInArray = data.inputArrayValue(aBlender);
const unsigned nStartElement = hInArray.elementIndex();
do {
    MDataHandle hIn = hInArray.inputValue();
    double bVal = hIn.asDouble();
    // do stuff
} while(hInArray.next() == MS::kSuccess);

Or if you want the plug index relating to the index of the output plug being requested:

MStatus myNode::compute (const MPlug& plug, MDataBlock& data) 
{
    unsigned multiIndex = plug.logicalIndex( );
    MArrayDataHandle hInArray = data.inputArrayValue(aBlender);
    hInputArray.jumpToElement( multiIndex );
    MDataHandle hIn = hInArray.inputValue();
    double bVal = hIn.asDouble();
    // do stuff and set output etc.
}

Well I left out all the error checking etc. Hope it helps

j

or Cancel