Hi,
thanks so much for answering. I have tried what you said, I read thet 
getValue is not possible to use in python, and that asMObject has to.
But the results are the same. I'm having the translation of the current 
frame.
Here it is my code in python:

        if( pPlug == DirectionMovNode.dirXAttribute ):
            # Get our custom input node attributes and values.
            inputMeshHandle = pDataBlock.inputValue( 
DirectionMovNode.inputMeshAttribute 
)
            inputMeshObj = inputMeshHandle.asMesh()
            meshFn = OpenMaya.MFnMesh(inputMeshObj)
            
            transFn = OpenMaya.MFnDagNode  (meshFn.dagPath())
            matrixPlugArray = transFn.findPlug("worldMatrix")
            matrixPlugArray.evaluateNumElements()
            matrixPlug = matrixPlugArray.elementByPhysicalIndex(0)
            time = OpenMayaAnim.MAnimControl.currentTime()
            timeContext = OpenMaya.MDGContext(time-1)
            matrixO = matrixPlug.asMObject(timeContext)
            fnMat = OpenMaya.MFnMatrixData(matrixO)
            matrix =  fnMat.matrix()
            result = '% .06f, % .06f, % .06f, % .06f,\n% .06f, % .06f, % 
.06f, % .06f,\n% .06f, % .06f, % .06f, % .06f,\n% .06f, % .06f, % .06f, % 
.06f,\n'
            print result % (matrix(0, 0), matrix(0, 1), matrix(0, 2), matrix
(0, 3), matrix(1, 0), matrix(1, 1), matrix(1, 2), matrix(1, 3), matrix(2, 0
), matrix(2, 1), matrix(2, 2 ), matrix(2, 3), matrix(3, 0), matrix(3, 1), 
matrix(3, 2), matrix(3, 3)) 
            
            # Set the output data.
            dirX = pDataBlock.outputValue( DirectionMovNode.dirXAttribute )
            dirX.setFloat(matrix(3, 0))

            



El lunes, 1 de mayo de 2017, 6:06:11 (UTC+2), Michael Boon escribió:
>
> I've done a similar thing successfully in Python, but I used 
> MPlug::asMObject and MFnMatrixData::matrix instead of MPlug::getValue. I 
> don't remember if I tried using getValue, but I do remember that I found it 
> extremely finicky and I tried a lot of approaches before I found one that 
> gave me a result. Maybe this approach will work for you too.
>
> This is in Python, but I think it will translate to C++:
>
>         matMObj = matrixPlug.asMObject(timeContext)
>         mat = om.MFnMatrixData(matMObj).matrix()
>
>
>
>
> On Monday, 1 May 2017 04:50:34 UTC+10, David DeJuan wrote:
>>
>> Hi,
>> I'm trying to do a Node, where the input is a mesh and get the 
>> translation matrix of it in the previous frame. But I don't get it.
>> I have tried using the MPlug getValue setting the MDGContext one frame 
>> before, but it doesn't work. 
>> This is the code, it is in C++
>>
>> MStatus node::compute(const MPlug& plug, MDataBlock& data){
>>
>> if (plug == dirX) {
>> MDataHandle dirXHandle = data.outputValue(dirX);
>> MDataHandle dirXHandleOld = data.outputValue(dirXOld);
>> MTime time = MAnimControl::currentTime();
>>
>> MDGContext timeContextOld(time - 1);
>>
>> MObject inputMeshObj = inputMeshHandle.asMesh();
>> MFnMesh meshFn(inputMeshObj);
>>
>> MDagPath dagPath;
>> dagPath = meshFn.dagPath();
>> MFnDagNode transFn(dagPath);
>>
>> MPlug matrixPlugArray = transFn.findPlug("worldMatrix");
>> matrixPlugArray.evaluateNumElements();
>> MPlug matrixPlug = matrixPlugArray.elementByPhysicalIndex(0);
>>
>> MObject matrixO;
>> matrixPlug.getValue(matrixO, timeContextOld);
>> MFnMatrixData fnMat(matrixO);
>> MVector res = fnMat.transformation().getTranslation(MSpace::kWor ld);
>>
>> // Set the output data.
>> dirXHandle.setFloat(0.0);
>> dirXHandleOld.setFloat(res.x);
>> }else {
>> return MS::kUnknownParameter;
>> }
>>
>> return MS::kSuccess;
>> }
>>
>>
>> I am wondering also how the cacheFrame node works.
>> Can anyone help me?
>> Thanks
>>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/f344de8b-cdce-48cb-9338-c89cb3a3646a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to