A callback is something you can setup to watch a specific behaviour, and when that behaviour is performed you do something special which is out of the normal behaviour or functionality of MotionBuilder (or Maya).
Here is my everyday English example of a callbacks :)
You assign me to watch a front door, and when people come in the door I hand them a visitor pass, without me watching the front door people would just come through the door and never get a visitors pass.
- Kristine = callback
- front door = MotionBuilder
- visitor pass = is the something special behaviour
So in MotionBuilder (or Maya), let’s say I want everyone to follow a special naming convention for their scene files, then I would set up a callback to watch anytime someone creates a new file. Then when this happens MotionBuilder calls a function in my code to save the file with a special name.
A very important thing to point out is that callbacks are efficient in MotionBuilder and Maya, so you do not need to be concerned, that they will slow down the application even though a callback is always watching what you told it to watch.
Callbacks allow you to add an personal level of customization to your production, studio or project. Since we cannot anticipate all the different usages of callbacks we just keep it very open where you can monitor most things in MotionBuilder and Maya. But having said this, this also means you must set the callbacks up yourself, since the combination of things to watch and things to do could be endless.
Another example is when someone changes a property, you maybe want to give them a warning…but how will you know when the user changes the property? They could do it at any time during their session usage, and you want the warning to be triggered right after they change it, not at a hard coded point of time... so here is where you want to setup a callback on property values, that will output a warning when this occurs.
Enjoy,
Kristine
Nice, thanks. Concerning Maya, I would really like to learn more about this. Are we just talking about scriptJobs here (that's the way I allways use(d) in scripts, even in python-times), or are there some other, 'more up to date' possibilities, e.g. using python and api?
Posted by: Felix | August 13, 2012 at 04:12 AM
Hi Kristine,
How would you register a callback on a newly created shapeNode's transform?
I want to have a callback added within a py node plugin:
def postConstructor(self):
nodeFn = OpenMaya.MFnDependencyNode(self.thisMObject())
nodeFn.setName("hape#" % self.typeName())
dpath = OpenMaya.MDagPath()
OpenMaya.MDagPath.getAPathTo(self.thisMObject(), dpath)
dpath.transform()
self._cbchild = OpenMaya.MDagMessage.addChildAddedDagPathCallback( dpath, self._childAdded, nodeFn )
The problem I'm having is that the transform's dag path is not recognized at this stage and the callback cannot be registered.
I cannot add the shape node's dagPath as I want to get a callback whenever a child is parented underneath the transform.
Do you have any solution to this issue?
Posted by: mtmy | August 15, 2012 at 07:26 AM
Hi Felix,
The concept of callbacks is somewhat general in Maya, then there is specific channels to implement them, as you mentioned ScriptJobs is definitely one way to do it, which can be accessed through MEL or Python Scripting commands.
And then another way to do it would be using the C++ or Python API, using the class MMessage and all the children classes located under it, you would choose a specific child class based on what functionality you wanted to watch and setup a call back on, you can take a look at the Maya API Docs online here for more information on MMessage and it's children classes:
http://usa.autodesk.com/adsk/servlet/item?id=16707768&siteID=123112
Also there is some good samples of this in the devkit that comes with Maya,
Hope that answers your question,
Kristine
Posted by: Kristine Middlemiss | August 17, 2012 at 12:11 PM
Hi mtmy
Adding a ChildAddedDagPathCallback is possible on DAG nodes only. If your node is not a DAG node and/or if the callback signature is not correct, the callback will not work.
I modified the rockingTransform node sample like below and I got a print on the Maya output window whenever I add a child to it. Let us know if you still experiencing an issue on your side.
Hope that helps
cyrille
def childAdded (dgchild, dgparent, clientData):
print "Hello World!"
class rockingTransformNode(OpenMayaMPx.MPxTransform):
def postConstructor(self):
thisNode = self.thisMObject()
dagFn =OpenMaya.MFnDagNode (thisNode);
dpath = OpenMaya.MDagPath()
dagFn.getPath (dpath)
print dpath.fullPathName()
self._cbchild =OpenMaya.MDagMessage.addChildAddedDagPathCallback(dpath, childAdded)
Posted by: Cyrille Fauvel | August 21, 2012 at 02:28 AM