Name changed callbacks in maya/python/api
- June 15th, 2011
- Posted in Maya
- Write comment
Could not figure this out for quite a while – maya API is a little obtuse if you’re not used to it, and with all the examples in c++, you’re on your own when it comes to translating to python. Ergh.
from maya import OpenMaya def nameChangedCallback( *args): node = args[0] # convert the MObject to a dep node depNode = OpenMaya.MFnDependencyNode(node) oldName = args[1] print '----\nNameChangedCallback' print 'newName: ', depNode.name() print 'oldName', oldName print 'type', depNode.typeName() # passing in a null MObject (ie, without a name as an argument) # registers the callback to get all name changes in the scene # if you wanted to monitor a specific object's name changes # you could pass a name to the MObject nullMObject = OpenMaya.MObject() OpenMaya.MNodeMessage.addNameChangedCallback( nullMObject, nameChangedCallback )