PDA

View Full Version : Simple Maya API question


westiemad
05-09-2005, 11:22 AM
Hi Guys,
I've just managed to write my first simple plugin (woo hoo), it adds two numbers together, yes I know, watch out ILM and WETA here I come. What I want to do is add an operation drop down so I can do other things to the 2 inputs, modulus, subtract, power etc, but I can't find which function or class to use to add it, any clues?

AnDy

chaoticbob
05-09-2005, 05:33 PM
You do this by adding an attribute to your node.

In your case, I think you wan an Enum Attribute, MFnEnumAttribute. It's pretty straight forward and works like you probably think it does.

...From an example on RobTheBloke.org

MFnEnumAttribute eAttr;

MObject oEnumValue = eAttr.create("longName", "shortName");

eAttr.addField("FirstSelection", 0);
eAttr.addField("SecondSelection", 1);
eAttr.addField("ThirdSelection", 2);
eAttr.addField("FourthSelection", 3);

eAttr.setReadable(true); // set the flag for readibiliy
eAttr.setKeyable(true); // set the flag for keyablility
eAttr.setWritable(true); // set the flag for writability

addAttribute(oEnumValue); // Add it to the node.

If you look up MFnEnumAttribute in the API Help, it has a pretty thorough
explanation of how it works.

Hope it helps.

westiemad
05-09-2005, 06:52 PM
Great, thanks for your help, I found the enum attribute by going through the examples, but I couldn't get it to show in the AE, I forgot to add that setreadable .

Thanks a ton, will read robs site also.

AnDy

westiemad
05-09-2005, 09:57 PM
any idea why this bit of code only updates output A, and ignores B and C (when the inputs are changed they remain at 0), they are initialized like below e.g.

inputB = aNumber.create("inputB", "inB", input1B, input2B, input3B);
aNumber.setStorable(true);
aNumber.setDefault( 0.0, 0.0, 0.0 );

with the attributeAffects as:
attributeAffects( inputB, output );


MStatus status;

if(plug == outputA || plug == outputB ||plug == outputC)

{

MDataHandle inputData1 = data.inputValue( inputA );

MDataHandle inputData2 = data.inputValue( inputB );

MDataHandle operation = data.inputValue ( selector );

double inp1 = inputData1.asDouble();

double inp2 = inputData2.asDouble();

short selType = operation.asShort();

MDataHandle outputData = data.outputValue( output );



2 inputs A and B each have an X Y and Z box each of which should affect output A B or C. Not sure if thats explained well or not.

AnDy

tweeeker
05-10-2005, 07:56 AM
Hmm, not sure, maybe it depends on how you have your compound attribute connected. You could try

attributeAffects( inputB, output );
attributeAffects( inputB, outputA);
attributeAffects( inputB, outputB);
attributeAffects( inputB, outputC);

so that when there's a plug to one of outputs children maya knows about it.

also adding the output attribute to the if statement that checks the plugs might be a good idea:
if(plug == output || plug == outputA || plug == outputB ||plug == outputC)

that way your covered if its the actual output plug requesting an update, rather than just the children.

T

westiemad
05-10-2005, 10:46 AM
i'm not sure whats wrong, i've split them up so the each have their own MFnNumericAttribute, done the attribute effects and tested for each plug, I'm wondering if its the:

MDataHandle inputData1 = data.inputValue( inputA );
MDataHandle inputData2 = data.inputValue( inputB );

double inp1 = inputData1.asDouble();
double inp2 = inputData2.asDouble();

but not sure how to solve that one, does it hunt for the specific value within inputA, or just the first one it comes across (e.g. the ones thats working input x), if so how would I get it to take the correct change and update the correct output.

AnDy

westiemad
05-10-2005, 11:16 AM
if I do a seperate (if plug ==outputA), then do all the handles and value setting, then another (if plug == outputB), and all the same code but with the specific inputs and outputs changed it works. Strange, unless I'm missing the point.


AnDy

tweeeker
05-10-2005, 08:41 PM
Sorry if I'm misunderstanding things here, but in an earlier post you created inputB with:

inputB = aNumber.create("inputB", "inB", input1B, input2B, input3B);

and now your trying to pick up it's value using

MDataHandle inputData2 = data.inputValue( inputB );
double inp2 = inputData2.asDouble();

The problem with that is inputB isn't a double, its a compound of 3 doubles (input1B, input2B, input3B) . I think thats why your only getting the first value. Instead try:

MDataHandle inputData2 = data.inputValue( inputB );
MVector inp2 = inputData2.asVector();
double inp2X = inp2.x; // x value;
double inp2Y = inp2.y; // y value;
double inp2Z = inp2.z; // z value;

Also, for clarity it might be better calling your attributes X,Y and Z instead of 1,2,3. i.e

inputB = aNumber.create("inputB", "inB", inputBX, inputBY, inputBZ);

hope that helps

T

westiemad
05-10-2005, 10:52 PM
thanks tweaker, for some reason it wasn't working, so I made the changes and played, and it still wasn't, I have spent most of the evening harrasing chaoticbob, who has taught me the power of the debugger, and it was puking on the if statment, enter a 1 and it works, then revert to plug == output, and for some reason it started to work.

Joy.

Thanks guys, until the next problem ;)

AnDy

CGTalk Moderation
05-10-2005, 10:52 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.