Hi, i am new to writing node plugins in python.
Sorry for the length of this question but it has got me stumped:
I am trying to create a MPxTransform node with an attatched MNodeMessage callback for any attribute change on that node. i am creating the callback like this: ("om" is my abrieviation for "OpenMaya)
[codebox]def createAttrChangedCallBack(node):
global messageIdSet
try:
cbID = om.MNodeMessage.addAttributeChangedCallback(node,attrChangedCB,clientData)
messageIdSet = True
return cbID
except:
messageIdSet = False
sys.stderr.write( "Failed to create CB and attatch -attrChangedCB- to: \n")[/codebox]
This does create the callback and attatch it to my MPxTransform node.
Then, in my user defined callback function (below), i want to test for the enum vlaue equated with "MNodeMessage.kAttributeSet"
(which happens to be "8", ..or on the autodesk website API reference "0x08")
[codebox]def attrChangedCB(msg,plug1,plug2,clientData):
correct\_msg = om.MNodeMessage.kAttributeSet
# correct\_msg happens to be enum value "8" when printed out in python
if msg == om.MNodeMessage.kAttributeSet:
# do stuff
else:
#report the message enum we actually recieved, which is not "8" (or "kAttributeSet")
[/codebox]
The message that is recieved is almost always: enum value "2052".. which does not have a corrisponding kMessage value listed in the docs..
The callback is triggered with this message -number "2052"-, way more often than i would expect. The callback function is called for every transform attr when the node is selected or deselected. it's called for every transform attr when only a single attr is selected or changed. If i select and change the vis attr, it is called for every transform attr sending this enum "2052". ..-but never a value (like ".kAttributeSet", or "8") listed in the docs as one of those that is supposed to be a trigger-.
Any activity on the node triggers multiple calls to the callback function in this way. Also moving the mouse accross the new "view orientation cube" in a perspective view triggers the callback for all of its transform attrs when the node is in the selection list.. (that one is really wierd).
It is as if the message enum values triggering and being sent to my callback function are not at all what is listed in the C++ docs. i never get a kAttributeSet, or kAttributeEval number.. or any number that is returned directly by om.MNodeMessage.kAttribute* when run in python..(these corrispond to the docs)
if i lock one of the attrs i get message enum number: "2064"
if i unlock that attr i get message enum number: "2080"
if i connect the .tx input of the node i get message enum number: "18433"
if i disconnect that attr i get message enum number: "18434"
..so some trigger events are going on besides message enum "2052"../ but none of the above message enums are listed in those that should trigger the callback. here are a list of the enums and there codes generated by python. these are also in the docs, although they are listed there as 0x01, 0x02,0x04,0x08 and so on.:
The expected behavior for attatching the MNodeMessage.addAttributeChangedCallback to my node is:
no event but those defined by "MNodeMessage.addAttributeChangedCallback" would be sent to the user defined callback function. one of those would be "kAttributeSet". i test for this specific event in the user defined callback, (event #"8"), and do stuff only when that event is calling my user defined callback.
questions:
1. what messages are enum Values "2052" and all the others that i get that are not documented, and how would i find out their actual function names?
2. why is attatching "OpenMaya.MNodeMessage.addAttributeChangedCallback" to my node sending anything other than "attribute changed" messages to my user define callback function?
3. why, when i actually do set a single attr on my plugin node, does the message enum value not equal "8", or "kAttributeSet" but continues to be "2052" and triggered for all transform attributes even when only one is changed?
thanks in advance for any help on this!
Sorry it is so long.
more of the code is of course available to anyone who can help.
-mt