Catching attributechanges through the maya api



I’m made a deformer plugin with the Maya api.
I have a string attribute that represents a path to a file.
I must read the file when the attibute is changed (or set).

How can I do this with the API?

I guess I could use a scriptjob that triggers a custom command to read the datafile…
But I’d rather trigger an event through the api with MNodeMessage and the kAttributeSet attributemessage.

I can’t find some good / simple example code (c++) that shows how to do this in practice.

Could someone help me out with a bit o examplecode please?
Is this the way to go or is there a risk to considerably slow down the plugin?
(I only need the callback when a particular attribute is changed / this particular attribute cannot be keyed and can be seen as a ‘one time thing’)

Can I generate an event for a particular attribute or is the event triggered for each attribute in the specified node?

Thx in advance.


Ok, that’s it

MCallbackId myCBID; 
void AttrChangedCB(MNodeMessage::AttributeMessage msg, MPlug & plug, MPlug & otherPlug, void* vpClientData)
if ( msg & MNodeMessage::kAttributeSet )
	 MGlobal::displayInfo(MString(; //Just 2 check which object.attribute has been altered
	 if(plug.attribute()==llsMddCacheReader::filePath) // filePath is the MOBject of the attribute
		 //Do your stuff
void myPlug::postConstructor()
   MStatus stat;
   MObject myNode = this->thisMObject();
   myCBID = MNodeMessage::addAttributeChangedCallback(myNode, AttrChangedCB, NULL, &stat);
// Remove CB in destructor


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.