how to get an MDagPath in a deformer, starting from the dataBlock ?

544 views
Skip to first unread message

fruity

unread,
Aug 9, 2016, 8:00:44 AM8/9/16
to Python Programming for Autodesk Maya


Hi there,

I'm prototyping a new deformer in python, and i'm stuck with a super stupid problem. So essentially, i need to get the dagPath of an object, and to do that, i have only an outMesh plug connected to my deformer. I have something that looks like that :

# this is what i get from my deformer
oSrcMesh
= dataBlock.inputValue(A.aSrcMesh).asMesh()
# get the dagPath - test 1
xxx
= OpenMaya.MDagPath()
OpenMaya.MDagPath.getAPathTo(oSrcMesh, xxx)
# get the dagPath - test 2
fnDag
= OpenMaya.MFnDagNode(oSrcMesh)



I won't go through everything i tried, but you get the idea ! I found NO way to get the dagPath of my mesh, starting from this oSrcMesh which is of type kMesh.
I think that my oSrcMesh is not aware of its hierarchy.

So what is the clean way of getting a MDagPath out of this oSrcMesh ?

This stupid pure maya api problem took me more time than everything else in this deformer, which is kind of a shame, so any help would be more than appreciated !
Many thanks =]

risto....@framestore.com

unread,
Aug 9, 2016, 5:18:00 PM8/9/16
to Python Programming for Autodesk Maya
Hi there.

You almost got it right :-)

First create a MfnDagNode from the mesh's MObject.

Something like:

MFnDagnode from om.Mobject ( oSrcMesh.node() )

Then you can pull MDagPath from MFnDagNode.getPath()

Hope this helps :-)

/risto

vincent...@gmail.com

unread,
Aug 9, 2016, 6:31:10 PM8/9/16
to Python Programming for Autodesk Maya, risto....@framestore.com
hehe, unfortunately that doesn't work ^^ This is what i tried, but the MObject is of type kMeshData, and not of type kMesh. Hence i can't initialize a MDagPath, that returns me an error saying that my MObject is of an incompatible type.

mlefevre

unread,
Aug 10, 2016, 3:12:12 PM8/10/16
to Python Programming for Autodesk Maya
I remember running into this issue before. Can you get the data you need without using an MDagPath object?

Maybe you can do what you need with something like asMeshTransformed() and geometryTransformMatrix() functions of MDataHandle.

fruity

unread,
Aug 10, 2016, 3:37:29 PM8/10/16
to Python Programming for Autodesk Maya
I didn't know asMeshTransformed() and geometryTransformMatrix(), nice =] However, same result, i'm afraid. The MObject is still of type kMeshData instead of kMesh, and i can't init a MFnDagNode with it (still "(kInvalidParameter): Object is incompatible with this method // ")
In the meantime, i have a workaround. I'm after the inclusiveMatrix of this mesh, so i just added a matrix attribute to the node, which is maybe even better, as i can set a different matrix. But i'd like to find a solution for that anyway, that seems too standard to not have a quick way of doing it !
Thanks for your help, anyway.

mjlefevre

unread,
Aug 11, 2016, 5:14:56 AM8/11/16
to Python Programming for Autodesk Maya
If you connect the worldMesh of your shape to your custom inMesh attribute, you can use geometryTransformMatrix() to grab the inclusive matrix I think.

fruity

unread,
Aug 13, 2016, 11:13:35 AM8/13/16
to Python Programming for Autodesk Maya
Yes, you're right ! Thank you ! If anyone has a solution to get a MDagPath from the inputGeom, anyway, i'd more than happy to hear it =]

f.michal

unread,
Aug 13, 2016, 12:19:15 PM8/13/16
to python_in...@googlegroups.com
Hi
I had this problem with my deformer too. I think what we try to do breaks Maya API rule saying that any dependency node can only depend on input attributes and nothing else. What we get inside deform() method is a geometry iterator - not shapeNode, not transform, not even meshData plug ! (meshData could be accessed if deformer was converted to some polyModifier node with meshData input attribute) !

This is how I solved this, but the drawback is that it fails as soon as I add any other deformer (which is not a disaster in my particular case).
I'd love to know if there's a better method. Keep in mind that I extracted following code from my plugin without testing:


MStatus xxx::deform(...)
{
    MObject thisNode(this->thisMObject());

    // -- OUTPUT GEOM
    MPlug outputPlug(thisNode, outputGeom);
    outputPlug.selectAncestorLogicalIndex(geomIndex);
    MPlugArray outputs_plugArr;
    outputPlug.connectedTo(outputs_plugArr, false, true);
    if(!outputs_plugArr.length()) {
        return MS::kSuccess;
    }
    outputPlug =  outputs_plugArr[0];
    MFnDependencyNode mesh_dn(outputPlug.node());
   
    MDagPath mesh_dagPath;
    MString pathToMesh = mesh_dagPath.getAPathTo(mesh_dn.object()).fullPathName();
}

-michal


W dniu 2016-08-09 o 14:00, fruity pisze:
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/0fc4bed6-d3f5-4d50-a1d2-1824cfbee399%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Reply all
Reply to author
Forward
0 new messages