We're having some issues with having to enter each render scene with "Load all References: ON" and saving the scene each time we add a new reference down the pipeline. These render scenes are tons and heavy nonetheless.
Is there any Pre Render MEL , flag or similar that could be used before rendering - so that Maya loads all references before render time?
Thanks in advance!
Solved! Go to Solution.
We're having some issues with having to enter each render scene with "Load all References: ON" and saving the scene each time we add a new reference down the pipeline. These render scenes are tons and heavy nonetheless.
Is there any Pre Render MEL , flag or similar that could be used before rendering - so that Maya loads all references before render time?
Thanks in advance!
Solved! Go to Solution.
Solved by viktor.hallen. Go to Solution.
So this was quickly tested, but this MEL should load all the references (sorry the formatting didn't copy over):
//===============================
global proc DD_loadRefs(){
//Load all Refs
string $allRefs[] = `file -q -r`;
for($i=0;$i<size($allRefs);$i++){
//Load Refs
if(`file -q -dr $allRefs[$i]`){
string $refNode = `referenceQuery -referenceNode $allRefs[$i]`;//Find Reference Node
file -loadReferenceDepth "all" -loadReference $refNode;//Load
}
}
}
//===============================
If you save that as a MEL script you can call it in a command line render using the -preRender flag. I haven't tested it in that scenario, but I don't see why it wouldn't work.
The one thing I would caution is that I've had issues calling MEL scripts in a command line render. The issue is usually that the .mel script doesn't get sourced properly. I force the .mel to be sourced be using the following:
-preRender "source \"myMelScript.mel\";DD_loadRefs();"
I'm on a mac, so the syntax may be different on a pc.
Hope this makes sense, let me know if you have issues....
So this was quickly tested, but this MEL should load all the references (sorry the formatting didn't copy over):
//===============================
global proc DD_loadRefs(){
//Load all Refs
string $allRefs[] = `file -q -r`;
for($i=0;$i<size($allRefs);$i++){
//Load Refs
if(`file -q -dr $allRefs[$i]`){
string $refNode = `referenceQuery -referenceNode $allRefs[$i]`;//Find Reference Node
file -loadReferenceDepth "all" -loadReference $refNode;//Load
}
}
}
//===============================
If you save that as a MEL script you can call it in a command line render using the -preRender flag. I haven't tested it in that scenario, but I don't see why it wouldn't work.
The one thing I would caution is that I've had issues calling MEL scripts in a command line render. The issue is usually that the .mel script doesn't get sourced properly. I force the .mel to be sourced be using the following:
-preRender "source \"myMelScript.mel\";DD_loadRefs();"
I'm on a mac, so the syntax may be different on a pc.
Hope this makes sense, let me know if you have issues....
Thanks for the help!
Right now the MEL script only seems to work for top references only. The second there is a hierarchy to the references it stops working. It basically does not find the references that are unloaded as they are not located within the scene itself.
This script below does the job though, instead of finding the unloaded references and loading loading them in, it unloads the top references and then loads in "all" reference depth.
//////////
proc loadAllRefs(){
//Create a list of all references in the scene
string $allRefs[] = `file -q -r`;
for($ref in $allRefs){
//Find the reference node of the reference
string $refNode = `referenceQuery -referenceNode $ref`;
//Unload the reference
file -unloadReference $refNode;
//Load all references in all depths
file -loadReferenceDepth "all" -loadReference $refNode;
}
}
loadAllRefs();
//////////
If you have any alternative options or thoughts I would love to hear them!
Thanks for the help!
Right now the MEL script only seems to work for top references only. The second there is a hierarchy to the references it stops working. It basically does not find the references that are unloaded as they are not located within the scene itself.
This script below does the job though, instead of finding the unloaded references and loading loading them in, it unloads the top references and then loads in "all" reference depth.
//////////
proc loadAllRefs(){
//Create a list of all references in the scene
string $allRefs[] = `file -q -r`;
for($ref in $allRefs){
//Find the reference node of the reference
string $refNode = `referenceQuery -referenceNode $ref`;
//Unload the reference
file -unloadReference $refNode;
//Load all references in all depths
file -loadReferenceDepth "all" -loadReference $refNode;
}
}
loadAllRefs();
//////////
If you have any alternative options or thoughts I would love to hear them!
Ah yes, sorry. I guess my script wouldn't work in that situation.
The only other thing I could offer is a loop that would open your scenes, apply your script, then save them. When you run it it will open a dialog to choose your scene files, it will keep opening the dialog until you hit cancel. It does this so that you can grab scenes from multiple directories.
Test this on some sample scenes first because the way it is set it will save your scene once the script runs, NOT save as. Also this was written on a mac, but I think all the syntax works on a PC as well. Hope it helps.
//================================================================================
// Get Multiple Scene File Paths
//================================================================================
global proc string[] DD_getMultiScene(){
string $scenes[];
string $RenderDirectory = `workspace -q -fullName`;
string $filter = "Maya Files (*.ma *.mb);;Maya ASCII (*.ma);;Maya Binary (*.mb)";
int $size = 1;
//Loop dialog until user cancels
while($size > 0){
string $getSceneFile[] = `fileDialog2 -fileMode 4 -dialogStyle 1 -dir $RenderDirectory -fileFilter $filter`;
$size = (size($getSceneFile));
$RenderDirectory = dirname($getSceneFile[0]);
for($i=0;$i<$size;$i++){$scenes[size($scenes)] = $getSceneFile[$i];}
}
return $scenes;
}
//================================================================================
// Open Scene, Execute script, save
//================================================================================
global proc DD_openApplySave(){
string $scenes[] = DD_getMultiScene();
//Progress Window
int $amount = 0;
progressWindow
-title "Multi-Scene Apply"
-progress $amount
-status "Progress: 0%"
-isInterruptable true;
//For each Scene
int $size = `size($scenes)`;
float $den = $size;
for($i=0;$i<$size;$i++){
// Check if the dialog has been cancelled
if(`progressWindow -query -isCancelled`){break;}
//Open File
file -f -options "v=0;" -ignoreVersion -o $scenes[$i];
//Execute Mel Script
loadAllRefs();
//Progress
float $num = ($i+1);
$amount = ($num/$den)*100;
//Save File
file -save;
//Edit Progress Window
progressWindow -edit
-title $scenes[$i]
-progress $amount
-status ("Progress: "+$amount+"%");
}
progressWindow -endProgress;
}
//================================================================================
// Load all refs
//================================================================================
global proc loadAllRefs(){
//Create a list of all references in the scene
string $allRefs[] = `file -q -r`;
for($ref in $allRefs){
//Find the reference node of the reference
string $refNode = `referenceQuery -referenceNode $ref`;
//Unload the reference
file -unloadReference $refNode;
//Load all references in all depths
file -loadReferenceDepth "all" -loadReference $refNode;
}
}
DD_openApplySave();
Ah yes, sorry. I guess my script wouldn't work in that situation.
The only other thing I could offer is a loop that would open your scenes, apply your script, then save them. When you run it it will open a dialog to choose your scene files, it will keep opening the dialog until you hit cancel. It does this so that you can grab scenes from multiple directories.
Test this on some sample scenes first because the way it is set it will save your scene once the script runs, NOT save as. Also this was written on a mac, but I think all the syntax works on a PC as well. Hope it helps.
//================================================================================
// Get Multiple Scene File Paths
//================================================================================
global proc string[] DD_getMultiScene(){
string $scenes[];
string $RenderDirectory = `workspace -q -fullName`;
string $filter = "Maya Files (*.ma *.mb);;Maya ASCII (*.ma);;Maya Binary (*.mb)";
int $size = 1;
//Loop dialog until user cancels
while($size > 0){
string $getSceneFile[] = `fileDialog2 -fileMode 4 -dialogStyle 1 -dir $RenderDirectory -fileFilter $filter`;
$size = (size($getSceneFile));
$RenderDirectory = dirname($getSceneFile[0]);
for($i=0;$i<$size;$i++){$scenes[size($scenes)] = $getSceneFile[$i];}
}
return $scenes;
}
//================================================================================
// Open Scene, Execute script, save
//================================================================================
global proc DD_openApplySave(){
string $scenes[] = DD_getMultiScene();
//Progress Window
int $amount = 0;
progressWindow
-title "Multi-Scene Apply"
-progress $amount
-status "Progress: 0%"
-isInterruptable true;
//For each Scene
int $size = `size($scenes)`;
float $den = $size;
for($i=0;$i<$size;$i++){
// Check if the dialog has been cancelled
if(`progressWindow -query -isCancelled`){break;}
//Open File
file -f -options "v=0;" -ignoreVersion -o $scenes[$i];
//Execute Mel Script
loadAllRefs();
//Progress
float $num = ($i+1);
$amount = ($num/$den)*100;
//Save File
file -save;
//Edit Progress Window
progressWindow -edit
-title $scenes[$i]
-progress $amount
-status ("Progress: "+$amount+"%");
}
progressWindow -endProgress;
}
//================================================================================
// Load all refs
//================================================================================
global proc loadAllRefs(){
//Create a list of all references in the scene
string $allRefs[] = `file -q -r`;
for($ref in $allRefs){
//Find the reference node of the reference
string $refNode = `referenceQuery -referenceNode $ref`;
//Unload the reference
file -unloadReference $refNode;
//Load all references in all depths
file -loadReferenceDepth "all" -loadReference $refNode;
}
}
DD_openApplySave();
Can't find what you're looking for? Ask the community or share your knowledge.