Consider the following Python example
import maya.OpenMaya as OM import maya.cmds def test (msg, plug, otherplug, *clientData): if msg & maya.OpenMaya.MNodeMessage.kConnectionMade: print "connection made" if msg & maya.OpenMaya.MNodeMessage.kConnectionBroken: print "connection broken" if msg & maya.OpenMaya.MNodeMessage.kAttributeEval: print "attribute eval" if msg & maya.OpenMaya.MNodeMessage.kAttributeSet: print "attribute set" if msg & maya.OpenMaya.MNodeMessage.kAttributeLocked: print "attribute locked" if msg & maya.OpenMaya.MNodeMessage.kAttributeUnlocked: print "attribute unlocked" if msg & maya.OpenMaya.MNodeMessage.kAttributeAdded: print "attribute added" if msg & maya.OpenMaya.MNodeMessage.kAttributeRemoved: print "attribute removed" if msg & maya.OpenMaya.MNodeMessage.kAttributeRenamed: print "attribute renamed" if msg & maya.OpenMaya.MNodeMessage.kOtherPlugSet: print "attribute other plug set" plugName =str (plug.partialName ()) print "attrName: ", plugName print "" node =maya.cmds.createNode ("addDoubleLinear") sel =OM.MSelectionList () sel.add (node) obj =OM.MObject () sel.getDependNode (0, obj) OM.MNodeMessage.addAttributeChangedCallback (obj, test) # attribute added maya.cmds.addAttr (node, sn="test") # connection made; other plug set maya.cmds.connectAttr (node + ".test", node + ".i1") # attribute set ; attribute eval maya.cmds.setAttr (node + ".test", 1) # no callback triggered maya.cmds.getAttr (node + ".test") maya.cmds.getAttr (node + ".i1") # connection broken; other plug set maya.cmds.disconnectAttr (node + ".test", node + ".i1") # attribute locked maya.cmds.setAttr (node + ".test", lock=True) # attribute unlocked maya.cmds.setAttr (node + ".test", lock=False) # no callback triggered maya.cmds.renameAttr (node + ".test", "testing") maya.cmds.addAttr (node + ".testing", e=True, nn="test2") # attribute removed maya.cmds.deleteAttr (node + ".testing")
it will produce the following output
attribute added attrName: test connection made attribute other plug set attrName: test connection made attribute other plug set attrName: i1 attribute set attrName: test attribute eval attrName: test connection broken attribute other plug set attrName: test connection broken attribute other plug set attrName: i1 attribute locked attrName: test attribute unlocked attrName: test attribute removed attrName: testing
What you can notice is while the SDK doc says the event will be triggered when an attribute has been renamed, the event was not called when we renamed the attribute. From the log above, you can see it never gets invoked when a dynamic attribute name is changed. (a static node attribute cannot be renamed anyway, so it applies only to dynamic attributes)
However this message is triggered while you set/change an attribute name alias using the aliasAttr command. For example, 'maya.cmds.aliasAttr ("testAlias", "addDoubleLinear1.i1")', and notice the output of the attribute rename callback.
The message is only sent when the name of an alias is changed. It doesn’t appear any messages are sent when the renameAttr command changes a dynamic attribute’s name. Editing the attribute’s nice name is not considered a rename in either case, it is done a different way.
Unfortunately, there is no way at this time to detect the name changed. This is a documentation defect which needs to be addressed.
(Contribution from Zhong Wu)
Comments
You can follow this conversation by subscribing to the comment feed for this post.