Can get maya node to show output


#1

Hi guys,

Being totally new to the API in maya I have done one of the code examples from the help file. Although I can’t get it to run, and I don’t know why. Its modified from the one that takes a sin of the input and outputs its value, the thing is that didn’t work either, I can load and unload the plug, and no errors appear anywhere. I however cannot see the output in the attribute editor, or when I use getAttr “mult.ouput” i just get the result as 0, even adding a custom attribute in maya and using the connection editor to connect the nodes output to another still displays nothing, can you guys give me some help and guidance please.

To run use I createNode mult;

 
#define REQUIRE_IOSTREAM
 
#include <string>
 
#include <iostream>
 
#include <math.h>
 
#include <maya/MString.h>
 
#include <maya/MFnPlugin.h>
 
#include <maya/MPxNode.h> 
 
#include <maya/MTypeId.h> 
 
#include <maya/MPlug.h>
 
#include <maya/MDataBlock.h>
 
#include <maya/MDataHandle.h>
 
#include <maya/MFnNumericAttribute.h>
 
class mult : public MPxNode
 
{
 
public:
 
mult();
 
virtual ~mult();
 
virtual MStatus compute(const MPlug &plug, MDataBlock &data);
 
staticvoid* creator();
 
static MStatus initialize();
 
public:
 
static MObject input1;
 
static MObject input2;
 
static MObject output;
 
static MObject text;
 
static MTypeId id;
 
};
 
MTypeId mult::id( 0x80000 );
 
MObject mult::input1;
 
MObject mult::input2;
 
MObject mult::text;
 
MObject mult::output;
 
void* mult::creator(){
 
returnnew mult;
 
}
 
MStatus mult::initialize(){
 
MFnNumericAttribute nAttr;
 
output = nAttr.create( "output", "out", MFnNumericData::kFloat, 0.0);
 
nAttr.setWritable(false);
 
nAttr.setStorable(false);
 
input1 = nAttr.create ( "input1", "in1", MFnNumericData::kFloat, 0.0);
 
nAttr.setStorable(true);
 
input2 = nAttr.create ( "input2", "in2", MFnNumericData::kFloat, 0.0);
 
nAttr.setStorable(true);
 
mytext =
 
addAttribute( input1 );
 
attributeAffects( input1, output );
 
addAttribute( input2 );
 
attributeAffects( input2, output );
 
addAttribute( output );
 
return MS::kSuccess;
 
}
 
mult::mult(){};
 
mult::~mult(){};
 
MStatus mult::compute( const MPlug &plug, MDataBlock &data) {
 
MStatus returnStatus;
 
if(plug == output)
 
{
 
MDataHandle inputData1 = data.inputValue( input1, &returnStatus );
 
MDataHandle inputData2 = data.inputValue( input2, &returnStatus );
 
if( returnStatus != MS::kSuccess)
 
cerr << "Error getting data" << endl;
 
else
 
{
 
float result = (inputData1.asFloat()) * (inputData2.asFloat());
 
MDataHandle outputHandle = data.outputValue( output );
 
outputHandle.set(result);
 
data.setClean(plug);
 
}
 
}
 
return MS::kSuccess;
 
}
 
MStatus initializePlugin( MObject obj) {
 
MStatus status;
 
MFnPlugin plugin( obj, "My plug-in", "1.0", "Any");
 
status = plugin.registerNode( "mult", mult::id, mult::creator, mult::initialize );
 
return status;
 
}
 
MStatus uninitializePlugin( MObject obj) {
 
MStatus status;
 
MFnPlugin plugin( obj );
 
status = plugin.deregisterNode( mult::id );
 
return status;
 
}
 

Treate me like a 5 year old.

AnDy


#2

I think you might want to add all of the attributes before calling attributeAffects(). Everything else seems OK.

Whilst this is still in the development stages, this may help

http://maya.robthebloke.org

The source code zip includes a simple node thats even simpler than the example you are starting from, a single input and single output. The notes may help as well… :wink:

rob


#3

you might also find that it doesn’t update the output unless another node is using it as an input…


#4

thanks for the reply Rob, and what a handy site :), i’ll have a play today and see if I can get it working.

Oddly enough, I was talking to a friend who had done the MSc at bournemouth, and was toying with the idea of going in 2005.


#5

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.