getReferenceFileByNode() -> MStatus::kInvalidParameter

getReferenceFileByNode() -> MStatus::kInvalidParameter

Anonymous
Not applicable
356 Views
1 Reply
Message 1 of 2

getReferenceFileByNode() -> MStatus::kInvalidParameter

Anonymous
Not applicable
I'm having some problems with MFileIO::getReferenceFileByNode(MObject& referenceNode, MStatus *returnStatus) whereby passed parameter 'returnStatus' is being set to MStatus::kInvalidParameter.

I presume this is supposed to happen when 'referenceNode' is not actually from a referenced file however I'm calling MFnDependencyNode::isFromReferencedFile() on the same node and it is returning true.

Here is an excerpt:

MDagPath dagPath;
if (itDag.getPath(dagPath) != MStatus::kSuccess)
return (false);

MFnMesh mesh(dagPath, &status);
if (status != MStatus::kSuccess)
return (false);

if (mesh.isFromReferencedFile(&status) && status == MStatus::kSuccess)
{
MObject node = mesh.object(&status);
if (status != MStatus::kSuccess)
return (false);

MString filename = MFileIO::getReferenceFileByNode(node, &status);
if (status != MStatus::kSuccess)
return (false); // <--- Reaching here.
}


I tried the following just for testing purposes and it worked as expected. i.e. The filename expected above was found.
MStringArray referencedFilenames;
MFileIO::getReferences(referencedFilenames);

for (int i = 0; i < referencedFilenames.length(); i++)
{
const char *referencedFilename = referencedFilenames.asChar();
}


Is there some circumstance whereby mesh.isFromReferencedFile&#40;&#41; would return true and MFileIO::getReferenceFileByNode() not work. Do I have to do something first to make MFileIO::getReferenceFileByNode() work?

Any help would be very much appreciated.
Thanks
0 Likes
357 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
For future reference to anyone experiencing the same problem. It looks as though there is a bug in the Maya API or at least a documentation error.

The workaround is to call the equivalent MEL command as follows:

char *command = new char;
sprintf(command, "%s %s", "referenceQuery -filename", mesh.name().asChar());

MCommandResult result;
MGlobal::executeCommand(command, result);

delete [] command;

MString referenceFilename = result.stringResult(&status);
if (status != MStatus::kSuccess)
{
error("Failed to get filename of referenced mesh");
return (false);
}
0 Likes