Query which file type / file translator was used to create a reference?

barnabas79
Contributor
Contributor

Query which file type / file translator was used to create a reference?

barnabas79
Contributor
Contributor

If I have a loaded reference node, I would like to find what the file type was - ie, if the reference was created with this command:


file -reference -type fooImporter "/path/to/myFile.foo"

I want to query myFileRN to get "fooImporter".


Ideally, I'd prefer an OpenMaya solution, but mel / maya.cmds would be fine too...

 

0 Likes
Reply
Accepted solutions (1)
697 Views
6 Replies
Replies (6)

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

I think you can use MFileIO::getReferneceNodes and MFnDependencyNode::typeName to get the referencing nodes' names.

 

If you are going to write in Python, the MFileIO isn't available. You can use cmds.file to query all references instead.

 

Yours,

Li

0 Likes

barnabas79
Contributor
Contributor

MFnDependencyNode::typeName() gives the maya node type name - ie, "transform", "joint", "mesh", etc.

 

I'm looking for the translator / MPxFileTranslator name - ie, "mayaAscii", "mayaBinary", "abcImport", etc.

0 Likes

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

In that case, you can use cmds.referenceQuery to get the filenames and use file -q -typ file name to get the file type. You could also get a custom MPxFileTranslator* with MFileIO.

 

If you know the plugin name of the translator you are using, you can use plugininfo with translator flag to get the translators' name.

 

Yours,

Li

0 Likes

barnabas79
Contributor
Contributor

Multiple plugins / file translators can register themselves for the same extension - thus the need to know what the exact translator used was.  (In my case, there are multiple translators for the ".abc" format, and I want to know which was used.)

Getting an MPxFileTranslator*, while still not ideal (ie, wouldn't work for any built-in maya types), would probably be good enough.  However, for my needs it would probably be good enough.  Is the method you're referring to MFileIO::beforeReferenceUserFileTranslator()?  If so, this (and many other referencing callbacks) have an achilles heel - there's no way I know of to directly query which reference is being currently loaded in a unique way.  You can use beforeReferenceFilename() to get the name of the file, but that's not unique - you could can reference in the exact same file multiple times, and I don't know how to distinguish which reference we're currently loading.

 

Having said that - in order for that to be an issue, it would mean that we'd have to be loading the exact same file multiple times, but with DIFFERENT translators... ie, do something like:

file -reference "myFile.abc" -namespace "nativeAlem" -type "Alembic";
file -reference "myFile.abc" -namespace "usdAlem" -type "pxrUsdImport";

...which seems unlikely. So this may be our best option...

0 Likes

cheng_xi_li
Autodesk Support
Autodesk Support
Accepted solution

Hi,

 

Yes, I was referring to MFileIO::beforeReferenceUserFileTranslator. The isn't a direct query available right now.

 

I am afraid there are no other methods to get the translator type of a reference node.  Sorry for the bad news.

 

Yours,

Li

0 Likes

barnabas79
Contributor
Contributor

Gotcha - well, thanks for the info!  beforeReferenceUserFileTranslator isn't perfect, but will hopefully be good enough!

0 Likes