View Full Version : Query loaded references

09-17-2011, 10:48 PM
Hey everyone,

I was wondering if anyone out there knows of a way to either:

A. Import all loaded references (but not the ones that aren't loaded) within a scene using mel

B. query what references are loaded in the scene using mel

I appreciate any help. I wasn't expecting to have such a difficult time with this. I'll keep trying to see if there's some super obvious thing that I am overlooking.

09-17-2011, 11:45 PM
The "referenceQuery" command can be used to list the references. The "file" command can be used to load references, convert references into imports and a slew of other things.

I would think some combination of these two MEL commands could be used to address whatever specific thing you are trying to achieve.

<* Wes *>

09-18-2011, 03:50 AM
I looked into both of them before the original post, but couldn't find a quick and easy way.

I think that I might have found a work around using the file and catch commands tho. I'll post my results if I can get it to work.

Thanks for the input.

09-18-2011, 05:09 AM
I have used
file -ir "filename.ma"
to convert a reference to an import. I haven't used referenceQuery before, but the docs say that -f returns the filenames, so a loop with these two should convert them all.

<* Wes *>

09-18-2011, 06:13 AM
I see what you mean, but It errors out if the reference is not loaded (unchecked in the reference editor).

it's important that I don't have any errors, because this is a batch editing script that I'm writing. So if there is an error, it will stop the script in its tracks, and it won't edit any other files in the list.

That's why I was thinking of using "catch", but it gets a little trickier, because sometimes there are nested references. When you import from a reference that has another reference inside of it, then that one needs to be imported too.

The way that I would prefer to do it, would be to find a way to figure out which references, in the scene, are currently loaded (checked in the referenced editor).

09-18-2011, 07:52 AM
It works now:

global proc importLoadedReferences()

int $caught=1;
int $keepGoing=1;

string $sceneName = `file -q -sn`;

while ($keepGoing > 0)

string $topLvlRefs[] =`file -q -r $sceneName`;

for ($ref in $topLvlRefs)
$caught=catch(`file -ir $ref`);

if ($caught==0)


If there is a quicker and easier way of knowing which references are loaded and which ones aren't I would still be super interested in finding out.

09-18-2011, 11:31 AM
In mel you can use the deferred flag to check if a reference is loaded or not. All of this is 500% easier if you switch to PyMel as all the reference handling is fabulous in it and makes life so much easier. Anyway, heres the query we used to use:

string $refs[] = `file -q -r`;

for ( $ref in $refs )
//If Reference is not deferred, then it is loaded
if ( !`file -q -dr $ref` )
print $ref;

09-18-2011, 05:38 PM
Thank you markj! That's the better way to do it.

I know that I looked at that flag before posting, but I think that I was using it in tandem with the -reference flag or something. So it either wasn't working, or it was erroring out.

I am definitely interested in learning pymel, but it's not part of the pipeline at work, and was thinking about learning some math (my greatest enemy) before tackling pymel, python, or various flavors of C.

CGTalk Moderation
09-18-2011, 05:38 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.