CODE
// Get the position of the target point.
MDataHandle mdhTarget = mdbData.inputValue(m_moTarget);
MMatrix mmTarget = mdhTarget.asMatrix();
MPoint mpTarget(mmTarget[3][0], mmTarget[3][1], mmTarget[3][2]);
// Get the inverse transformation matrix of this node:
MDagPath mdpThis;
MFnDagNode mfdnThis(thisMObject());
mfdnThis.getPath(mdpThis);
MMatrix mmMatrix = mdpThis.inclusiveMatrix();
MMatrix mmMatrixInverse = mmMatrix.inverse();
// Express the target point in this node's object space:
MPoint mpTargetInThisSpace(mpTarget * mmMatrixInverse);
// Assuming that the vector 1, 0, 0 defines the position of the front of this node,
// get the quaternion that describes the rotation to make that vector point to mpTargetInThisSpace:
MQuaternion mqToTarget(MVector(1.0,0.0,0.0).rotateTo(MVector(mpTargetInThisSpace)));
// Apply that rotation to this node:
MFnTransform mftThis(mdpThis.transform());
mftThis.rotateBy(mqToTarget, MSpace::kPreTransform);
// Get the new inverse transformation matrix of this node
/*MMatrix*/ mmMatrix = mdpThis.inclusiveMatrix();
/*MMatrix*/ mmMatrixInverse = mmMatrix.inverse();
// Get the world up vector.
MDataHandle mdhUp = mdbData.inputValue(m_moUpX);
MVector mvUp = mdhUp.asVector();
// Express the world up vector in this node's object space.
MPoint mpWorldUpInThisSpace(mvUp * mmMatrixInverse);
// Get the quaternion that describes the rotation to make the local up vector point to the world up vector:
MQuaternion mqToWorldUp(MVector(MVector(0.0, 1.0, 0.0)).rotateTo(MVector(mpWorldUpInThisSpace)));
// Get the x-axis rotation from the quaternion
MEulerRotation merToWorldUp(mqToWorldUp.asEulerRotation());
merToWorldUp.y = 0.0;
merToWorldUp.z = 0.0;
// Apply that rotation to this node:
mftThis.rotateBy(merToWorldUp, MSpace::kPreTransform);
Hope it helped.