March 2019: ewertb.soundlinker.com is getting relocated to ewertb.mayasound.com, please update your bookmarks.

MEL How-To #02

Back · Previous · Next Maya

How do I determine which Reference files are currently defined or loaded? How do I load and unload them?

To find out which References exist for the currently loaded file:

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

To find out which are loaded (ie. not deferred):

proc string[] referencesLoaded()
{
   string $referencesLoaded[];
   int $numLoaded = 0;

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

   for ( $ref in $refs )
   {
      // If Reference is not deferred, then it is loaded
      if ( !`file -q -dr $ref` )
         $referencesLoaded[$numLoaded++] = $ref;
   }
   return $referencesLoaded;
}

To unload all references (this won't delete them from the Reference Editor):

proc unloadReferences()
{
   string $referencesLoaded[] = referencesLoaded();
   string $refNode;

   for ( $refFile in $referencesLoaded )
   {
      // Need to get node that identifies reference
      $refNode = `file -q -rfn $refFile`;

      // Now you can unload it
      file -ur $refNode $refFile;
   }
}

To physically delete loaded references from the scene and the Reference Editor:

proc deleteLoadedReferences()
{
   string $referencesLoaded[] = referencesLoaded();

   for ( $refFile in $referencesLoaded )
   {
      file -rr $refFile;
   }
}

And finally, to delete all References:

proc deleteAllReferences()
{
   string $references = `file -q -r`;

   for ( $refFile in $references )
   {
      file -rr $refFile;
   }
}