therrell
12-04-2008, 07:03 PM
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 an 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)
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")
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 in python is returned as 8, ..or on the autodesk website C++ API reference "0x08")
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")
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"
output:
kConnectionMade : 1
kConnectionBroken : 2
kAttributeEval : 4
kAttributeset : 8
kAttributeLocked : 16
kAttributeRemoved : 128
kAttributeRenamed : 256
kAttributeKeyable : 512
kAttributeUnkeyable : 1024
kIncomingDirection : 2048
kAttributeArrayAdded : 4096
kAttributeArrayRemoved : 8192
kOtherPlugSet : 16384
kLast : 32768
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
Sorry for the length of this question but it has got me stumped:
I am trying to create an 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)
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")
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 in python is returned as 8, ..or on the autodesk website C++ API reference "0x08")
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")
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"
output:
kConnectionMade : 1
kConnectionBroken : 2
kAttributeEval : 4
kAttributeset : 8
kAttributeLocked : 16
kAttributeRemoved : 128
kAttributeRenamed : 256
kAttributeKeyable : 512
kAttributeUnkeyable : 1024
kIncomingDirection : 2048
kAttributeArrayAdded : 4096
kAttributeArrayRemoved : 8192
kOtherPlugSet : 16384
kLast : 32768
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
