Laurent Crivello
Laurent Crivello

Reputation: 3931

Pass custom data to attributes of MPxLocator (Maya API)

In a cpp class using Maya API, I initiate a custom MPxLocator instance called myLocatorNode and pass its attributes some variables:

MDagModifier dagMod;
MDGModifier mdgMod;

    myObj=dagMod.createNode("myLocatorNode", <existing transform MObject>);
    dagMod.doIt();

    MFnDagNode myDagNode(myObj);
    myDagNode.findPlug("attributeOne").setValue(1.5);
    myDagNode.findPlug("attributeTwo").setValue(2.0);
    myDagNode.findPlug("attributeThree").setValue(3.1);
    myDagNode.findPlug("classAttrib").setValue(classPointer); // <- which type should I use ?

Custom Locator class:

MStatus myLocatorNode::initialize()
{
    MFnNumericAttribute nAttr;
    MFn???Attribute customAttr;  <-- What can I use here ?

    attr1= nAttr.create( "attributeOne", "ao", MFnNumericData::kFloat,1.0 );
    attr2= nAttr.create( "attributeTwo", "ao", MFnNumericData::kFloat,1.0 );
    attr3= nAttr.create( "attributeThree", "ao", MFnNumericData::kFloat,1.0 );
    attr4= customAttr.create("classAttrib","ca", MyCustomClass *); <-- and here ?
        ...   

    }

I would like to pass to the attribute/plug the pointer to a custom class. Which attribute type in the locator class will help me doing that ? Thanks

Upvotes: 0

Views: 585

Answers (1)

cyrille
cyrille

Reputation: 2659

MFn???Attribute customAttr; <-- What can I use here ?

well, by class pointer you mean a memory address? on x64 bit machine a pointer is a int64, so you need to store a int64 integer. You can use the MFnNumericAttribute::createAddress() way or store your own int64 as described here: http://around-the-corner.typepad.com/adn/2012/11/no-64bit-integer-attribute-in-maya-no-way.html

Upvotes: 1

Related Questions