« Avoid Gimbal Lock for Rotation/Direction Maya Manipulators | Main | Convert Maya World Coordinates to Screen Coordinates »

August 13, 2012

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

Felix

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?

mtmy

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?

Kristine Middlemiss

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

Cyrille Fauvel

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)

The comments to this entry are closed.

The Authors
Cyrille Fauvel Lanh Hong Cheng Xi Li

SyntaxHighlighter