View Full Version : File name prefix and Layer names
Falott
25-07-2011, 04:13 PM
what first seemed to be an easy task turned out to break my head right now.
What I need to do is (for many many files and layers) to output rendered files in a special folder structure:
folder name = "myName"+"currentTime"
image name = renderLayer
I have no idea how to output files in these custom folders exept for <Layer><Scene><Camera><Version>, and the documentation is kind of a 2 sentence loop. (using maya 8.5) I also seems to be impossible to put mel code into the File name prefix input field..
many thanks in advance!
NextDesign
17-08-2011, 05:37 PM
myName being what? Your windows username?
Falott
20-08-2011, 06:15 AM
Hi pal,
"myName" will be derived from the textures used at render time. in this case:
textureFolder001
textureFolder002
.
.
.
textureFolder260
thanks for your participation!
NextDesign
20-08-2011, 07:55 PM
So for example, you have a texture folder named textureFolderA, and you're rendering frame 1, and rendering the diffuse pass. Should it look like this?
textureFolderA001/diffuse.tga?
What exactly are you trying to do?
Falott
21-08-2011, 09:47 AM
to be more precise:
I have a model of a shirt broken up into many different parts like torso (slim, medium, large, and different shapes), long and short sleeves, many different collars and cuffs. these objects are arranged on renderlayers to make a big PSD file out of all layers per texture. there will be 260 different textures which all have to be applied once to all geometry variations. I was thinking that objects (renderlayers) x textures (timeline) is a good way to start.
I need a one PSD file with all objects in single layers per texture in it. so in the end there will be 250 PSD files named like Pattern001.PSD, ..., Pattern260.PSD containing something like 200 layers called:
shirtFront1_slim_pattern132
..
shirtBack3_medium_pattern132
..
collar24_pattern132
..
cuff18_pattern132
I hope this helps to understand. I dont render passes with shadows, diffuse, specular, etc. just a complete beautypass per object (on renderlayers named like "shirtBack3_medium_", etc...) but I want to make maya output all layers in a per frame (per texture) way. then I could simply import all textures of one folder into Photoshop via Scripts-> Load Files into Stack. the layers will have the same name than the files. voilá! mission accomplished!
thanks!
NextDesign
21-08-2011, 04:08 PM
Sorry mate. Would it be possible for you to create a test file, so I can try to figure it out?
Falott
22-08-2011, 07:12 AM
if you´re so kind to invest your time, that would be really great. I´ll put a scene together for you later today. thanks a lot man!
Falott
22-08-2011, 08:32 AM
ok, here is a simple test scene. all geometry parts are assigned to the correspondent render layers. I´ve also added a info group node which tells again what I would need to do.
thanks for taking the time again!
NextDesign
23-08-2011, 03:10 AM
Cool, thanks. I'll take a look for ya!
Just to be clear, you want to use this on a renderfarm right? And is this the only way for this to work?
Falott
23-08-2011, 06:52 AM
that´s the only way I could imagine. if you find an easier solution, I´m up for anything that works. and in case of correctional work (which will come for sure!) I don´t want to make tons of manual changes. keep in mind that I have at least (because the project is growing since it started):
150 objects on 150 layers
260 textures on timeline
for each variation 3 camera perspectives (3 single scenes)
equals 1.170.000 stills for now.
a must is to have 1 folder for every texture containing all geometries, with the objects named after the layer they´re applied to.
NextDesign
23-08-2011, 05:49 PM
Hey Falott. This won't work on the farm, but it will work on your local machine. Better to have something being rendered while we try to figure this out :)
(Also, by the way, you have 17,550,000 renders in total. 150*150*260*3 :D)
Set your basePath, texturePath, first, and last frame, turn off file sequence and delete the expression in your texture, and you'll be good to go.
string $texture = ($texturePath + "shirt_" + $i + ".png");Is where you'll set the names of the textures (in this case, shirt_[firstFrame->lastFrame].png)
string $basePath = "G:/Projects2011/shirtTestScene/renderedTextures/";
string $texturePath = "G:/Projects2011/shirtTestScene/textures/";
int $firstFrame = 1;
int $lastFrame = 5;
string $renderLayers[] = `ls -type "renderLayer"`;
// do stuff
for ($i = $firstFrame; $i <= $lastFrame; $i++)
{
string $folderName = ("pattern" + $i);
string $texture = ($texturePath + "shirt_" + $i + ".png");
// change texture
setAttr -type "string" file1.fileTextureName $texture;
for ($layer in $renderLayers)
{
if ($layer == "defaultRenderLayer") // ignore the default render layer
continue;
else
{
string $folder = ($basePath + $folderName);
if (!`filetest -e $folder`) // folder doesn't exist. create it.
sysFile -makeDir ($basePath + $folderName);
print ($folder + "/" + $layer + $folderName + "\n");
render -l $layer; // render
catch(eval(renderWindowSaveImageCallback ($renderPanel, ($folder + "/" + $layer + $folderName), `getAttr defaultRenderGlobals.imageFormat`)));
}
}
}Hopefully it does what you want! :)
Falott
24-08-2011, 07:45 AM
OH MAN! THANK YOU!
unfortunately I can soonest try this script at the beginning of next week , because I am on vacation this week. :) but I will examine this script and try to understand it so I can kick it off asap. dude, this piece of code is appreciated so much!
the only thing I want to ask is, where do I put this mel code? into the preRender/preRender Frame section?
because if so - I can tell vertext muster to use this code as well, and everything would be fine.
NextDesign
24-08-2011, 05:48 PM
It's actually just run in your script editor. As I said, it won't work on the renderfarm, unless you send different scripts to each machine.
Eg.
Machine 1: startFrame = 1 endFrame = 10
Machine 2: startFrame = 11 endFrame = 20
Machine 3: startFrame = 21 endFrame = 30
...
You MIGHT be able to put this into the pre-render frame, with startFrame and endFrame set to `currentTime -q`
Falott
29-08-2011, 04:36 PM
after stealing some of your code from other places :D I have my script almost working as it should. there are a few things which still give me head ache though.
string $renderPanel;
string $renderPanels[] = `getPanel -scriptType "renderWindowPanel"`;
string $basePath = (`workspace -q -rd` + "renderOutput/");
string $renderLayers[] = `ls -type "renderLayer"`;
int $firstFrame = `currentTime -q`;
int $lastFrame = `currentTime -q`;
if(size($renderPanels))
$renderPanel = $renderPanels[0];
else
{
$renderPanel = `scriptedPanel -type "renderWindowPanel" -unParent renderView`;
scriptedPanel -e -label "Render View" $renderPanel;
}
// do stuff
for ($i = $firstFrame; $i <= $lastFrame; $i++)
{
// RenderViewWindow;
// tearOffPanel "Render View" "renderWindowPanel" true;
string $outputFolder = ("PSDmuster" + $i + "_");
string $myDiffuseTexture = "DT_" + `currentTime -q`;
string $myNormalTexture = "NM_" + `currentTime -q`;
//connectAttr -force ($myDiffuseTexture + ".outColor") shader_gamma.value;
//connectAttr -force ($myNormalTexture + ".outAlpha") shader_bump2d.bumpValue;
for ($layer in $renderLayers)
{
if ($layer == "defaultRenderLayer") // ignore the default render layer
continue;
else
{
string $folder = ($basePath + $outputFolder);
if (!`filetest -e $folder`) // folder doesn't exist. create it.
sysFile -makeDir ($basePath + $outputFolder);
print ($folder + "/" + $layer + $outputFolder + "\n");
render -l $layer shotCAM01; // render
if (`getApplicationVersionAsFloat` >= 2011)
catch(eval(renderWindowSaveImageCallback ($renderPanel, ($folder + "/" + $outputFolder + $layer), `getAttr defaultRenderGlobals.imageFormat`)));
else
renderWindowSaveImageCallback ($renderPanel, ($folder + "/" + $outputFolder + $layer), `getAttr defaultRenderGlobals.imageFormat`);
// catch(eval(renderWindowSaveImageCallback ($renderPanel, ($imagesDir + “/renderView.” + ($maxImageIndex – $i)), `getAttr defaultRenderGlobals.imageFormat`)));
}
}
}
#1
in case files get overwritten, how can I integrate an "auto-YES, please overwrite that file" into the script?
#2
# Error: AttributeError: ImageFormats instance has no attribute 'oldOutf' #
if I replace
`getAttr defaultRenderGlobals.imageFormat`
with
"PNG"
result:
// Error: //
// Error: Syntax error //
without any further information on that error
basically the directory is created, rendered frame is named and placed correctly, but it is black.
#3
//connectAttr -force ($myDiffuseTexture + ".outColor") shader_gamma.value;
//connectAttr -force ($myNormalTexture + ".outAlpha") shader_bump2d.bumpValue;
if the corresponding textures are already applied,
// Warning: 'DT_2.outColor' is already connected to 'shader_gamma.value'. //
and the script stops there. I tried to make use of the catch() command, but maya always returns
// Error: Invalid use of Maya object "connectAttr". //
NextDesign
30-08-2011, 03:05 PM
#1
in case files get overwritten, how can I integrate an "auto-YES, please overwrite that file" into the script?
Before "if (`getApplicationVersionAsFloat` >= 2011)", put:
string $renderedFilename = ($folder + "/" + $outputFolder + $layer);
if (`filetest -e $renderedFilename`) // image exists. delete it.
sysFile -del $renderedFilename;
#2
# Error: AttributeError: ImageFormats instance has no attribute 'oldOutf' #
if I replace
`getAttr defaultRenderGlobals.imageFormat`
with
"PNG"
result:
// Error: //
// Error: Syntax error //
The AttributeError is not a problem. It still renders.
Replace `getAttr defaultRenderGlobals.imageFormat` with 32 (the file extension enumeration index).
Eg.
renderWindowSaveImageCallback ($renderPanel, ($folder + "/" + $outputFolder + $layer), 32);
#3
connectAttr -force ($myDiffuseTexture + ".outColor") shader_gamma.value;
connectAttr -force ($myNormalTexture + ".outAlpha") shader_bump2d.bumpValue;
if the corresponding textures are already applied,
// Warning: 'DT_2.outColor' is already connected to 'shader_gamma.value'. //
and the script stops there. I tried to make use of the catch() command, but maya always returns
// Error: Invalid use of Maya object "connectAttr". //
Not sure what the problem is there. Did you put:
catch(eval(connectAttr -force ($myDiffuseTexture + ".outColor") shader_gamma.value));
?
Falott
31-08-2011, 08:24 AM
thank you so much for taking the time to help me.
unfortunately the 'oldOutf' error still persists.
string $renderedFilename = ($folder + "/" + $outputFolder + $layer);
if (`filetest -e $renderedFilename`) // image exists. delete it.
sysFile -del $renderedFilename;
doesn´t work either. I probably did something wrong.
but renderings are now outputted into specific folders + into the temp folder. weird...
I´ve tried all different kind of fu**Ups today with the scipt. it´s just getting worse..
C:/.../maya/renderOutput/PSDmuster1_/PSDmuster1_obj_A
# Error: file: C:/Program Files/Autodesk/Maya2011/scripts/others/renderWindowPanel.mel line 663: ImageFormats instance has no attribute 'oldOutf'
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# File "C:\Program Files\Autodesk\Maya2011\Python\lib\site-packages\maya\app\general\createImageFormats.py", line 185, in popRenderGlobals
# cmds.setAttr("defaultRenderGlobals.outf", self.oldOutf)
# AttributeError: ImageFormats instance has no attribute 'oldOutf' #
could it be that the renderWindowPanel.mel is hacked dead by the autodesk crew? just a question, lol - error is most likely on my side.
to make things easier I´ve added a very simplified projectFolder for you. I hope the script editor still holds executed script and error results when you open it. you´ll find the adapted mel script in the mel folder as well. I guess after a quick look at the scene from your side you´ll find a solution pretty fast.
PS: don´t mind the animated camera- and lightsetup. there will be 3 different scenes in the end with static cameras.
besides the annoying oldOutf error, I´d have one more question for you if I may:
to speed up rendertimes in the end I´d like to flag some renderlayers with -reg <int><int><int><int>
right now there is this for ($layer in $renderLayers) loop which takes all layers at once into account. what if i were to tell maya instead of
render -l $layer shotCAM01;
something like this
render -l obj_A shotCAM01;
render -l obj_B shotCAM01;
render -l obj_C shotCAM01 -reg <int><int><int><int>;
render -l obj_D shotCAM01 -reg <int><int><int><int>;
render -l obj_E shotCAM01 -reg <int><int><int><int>;
but still make the script pop out folder- and file names correctly? it is not a must, but it could save way more than 50% render time for this project.
all best for now! and I hope to stop stealing your time soon :D
NextDesign
31-08-2011, 11:58 PM
I said, the oldOutf error is not a problem. Ignore it. It's handled.
What do you mean by -reg<int><int><int><int>? There is no such flag.
Falott
01-09-2011, 04:05 AM
if you say it´s handled, then ok. just thought when maya renders 1 sec for each layer and creates a black image, while popping out these errors..
sorry, i meant:
-reg int int int int Set sub-region pixel boundary of the final image:
left, right, bottom, top
because there are a lot of small parts to be rendered. but again, it is no must. there are just 3 categories of objects to be rendered with sub-region boundary. for these I can create 3 different scene files with the script adapted like
render -l $layer -reg int int int int shotCAM01;
priority is to make mental ray render the images which it doesn´t yet. all renderings are black right now.
NextDesign
01-09-2011, 02:53 PM
Oh. You mean when you send it through the command line, not through MEL. That's what confused me.
Falott
01-09-2011, 03:19 PM
sorry for being so imprecise.. I am use to look at mel code for years, but I just start to really learn that right now, since there is a demand for it at my new office. I am a modeller/texturer, little bit of animator naturally. but here it´s all about rendering, and that´s a completely new field of work for me.
basically I dont need to send it over the render farm. would be nice though, but if that code works on local machines only and does what needs to be done I am absolutely fine with it.
else
if you ever need help with something modeling related at any time (be it reviewing tasks, testModels, whatever...) please don´t hesitate to ask me. I´d be happy to offer any kind of support. you´re really saving my life here dude! I couldn´t have done this without your help for sure.
all best!
NextDesign
01-09-2011, 09:19 PM
And they don't have a TD? Strange...
Also, usually if I knew this was for a studio, I'd charge. Don't worry about it this time though, my fault for not asking! :D
Here are the fixes.
string $basePath = "/usr/Desktop/maya/renderOutput/";
string $texturePath = "/usr/Desktop/maya/texture/";
string $textureFormat = "png";
string $renderLayers[] = `ls -type "renderLayer"`;
int $firstFrame = 1;
int $lastFrame = 2;
// check for render panel
string $renderPanel;
string $renderPanels[] = `getPanel -scriptType "renderWindowPanel"`;
if(size($renderPanels))
$renderPanel = $renderPanels[0];
else
{
$renderPanel = `scriptedPanel -type "renderWindowPanel" -unParent renderView`;
scriptedPanel -e -label "Render View" $renderPanel;
}
// get the image format in the render globals
int $format = `getAttr "defaultRenderGlobals.imageFormat"`;
string $extension = "";
switch($format)
{
case 0: $extension = "gif"; break;
case 1: $extension = "pic"; break;
case 2: $extension = "rla"; break;
case 3: $extension = "tif"; break;
case 4: $extension = "tif"; break;
case 5: $extension = "sgi"; break;
case 6: $extension = "als"; break;
case 7: $extension = "iff"; break;
case 8: $extension = "jpg"; break;
case 9: $extension = "eps"; break;
case 10: $extension = "iff"; break;
case 11: $extension = "cin"; break;
case 12: $extension = "yuv"; break;
case 13: $extension = "sgi"; break;
case 19: $extension = "tga"; break;
case 20: $extension = "bmp"; break;
case 22: $extension = "mov"; break;
case 30: $extension = "pntg"; break;
case 31: $extension = "psd"; break;
case 32: $extension = "png"; break;
case 33: $extension = "pict"; break;
case 34: $extension = "qtif"; break;
case 35: $extension = "dds"; break;
case 36: $extension = "psd"; break;
}
// do stuff
for ($i = $firstFrame; $i <= $lastFrame; $i++)
{
string $outputFolder = ("PSDmuster" + $i);
string $myDiffuseTexture = ($texturePath + "DT_" + $i + "." + $textureFormat);
string $myNormalTexture = ($texturePath + "NM_" + $i + "." + $textureFormat);
for ($layer in $renderLayers)
{
if ($layer == "defaultRenderLayer") // ignore the default render layer
continue;
else
{
string $folder = ($basePath + $outputFolder);
if (!`filetest -e $folder`) // folder doesn't exist. create it.
sysFile -makeDir ($basePath + $outputFolder);
string $renderedFilename = ($folder + "/" + $outputFolder + "_" + $layer);
if (`filetest -e ($renderedFilename + "." + $extension)`) // image exists. delete it.
sysFile -del ($renderedFilename + "." + $extension);
// change texture
setAttr -type "string" tex.fileTextureName $myDiffuseTexture;
// render - nasty hack
render -l $layer;
renderWindowRender redoPreviousRender renderView;
if (`getApplicationVersionAsFloat` >= 2011)
catch(eval(renderWindowSaveImageCallback ($renderPanel, $renderedFilename, $format)));
else
renderWindowSaveImageCallback ($renderPanel, $renderedFilename, $format);
}
}
}
Falott
05-09-2011, 03:36 PM
thank you man. I´ve altered the script just a tiny little. it´s working perfect now.
I will post a final version of the script here as soon as I have finished all model/texture work. then I will see if the texture node thing needs some adjustment. (I´ve added an extra attribute "textureRealName" to the fileNodes, since they have to be named according to timeline right now.)
string $renderCAM = "shotCAM01";
string $basePath = (`workspace -q -rd` + "renderOutput/");
string $textureFormat = "png";
string $renderLayers[] = `ls -type "renderLayer"`;
int $firstFrame = 1;
int $lastFrame = 3;
// check for render panel
string $renderPanel;
string $renderPanels[] = `getPanel -scriptType "renderWindowPanel"`;
if(size($renderPanels))
$renderPanel = $renderPanels[0];
else
{
$renderPanel = `scriptedPanel -type "renderWindowPanel" -unParent renderView`;
scriptedPanel -e -label "Render View" $renderPanel;
}
// get the image format in the render globals
int $format = `getAttr "defaultRenderGlobals.imageFormat"`;
string $extension = "";
switch($format)
{
case 0: $extension = "gif"; break;
case 1: $extension = "pic"; break;
case 2: $extension = "rla"; break;
case 3: $extension = "tif"; break;
case 4: $extension = "tif"; break;
case 5: $extension = "sgi"; break;
case 6: $extension = "als"; break;
case 7: $extension = "iff"; break;
case 8: $extension = "jpg"; break;
case 9: $extension = "eps"; break;
case 10: $extension = "iff"; break;
case 11: $extension = "cin"; break;
case 12: $extension = "yuv"; break;
case 13: $extension = "sgi"; break;
case 19: $extension = "tga"; break;
case 20: $extension = "bmp"; break;
case 22: $extension = "mov"; break;
case 30: $extension = "pntg"; break;
case 31: $extension = "psd"; break;
case 32: $extension = "png"; break;
case 33: $extension = "pict"; break;
case 34: $extension = "qtif"; break;
case 35: $extension = "dds"; break;
case 36: $extension = "psd"; break;
}
// do stuff
for ($i = $firstFrame; $i <= $lastFrame; $i++)
{
string $outputFolder = ("PSDmuster" + $i + "_" + $renderCAM);
string $textureNode = ("DT_" + $i);
for ($layer in $renderLayers)
{
if ($layer == "defaultRenderLayer") // ignore the default render layer
continue;
else
{
string $folder = ($basePath + $outputFolder);
if (!`filetest -e $folder`) // folder doesn't exist. create it.
sysFile -makeDir ($basePath + $outputFolder);
string $renderedFilename = ($folder + "/" + $outputFolder + "_" + $layer);
if (`filetest -e ($renderedFilename + "." + $extension)`) // image exists. delete it.
sysFile -del ($renderedFilename + "." + $extension);
catch(`connectAttr -force ($textureNode + ".outColor") shader_gamma.value`); // --> catch(`connectAttr`) <-- if fileTextureNode is already connected to gammaCorrectNode, continue.
// render - nasty hack
render -l $layer $renderCAM;
renderWindowRender redoPreviousRender renderView;
if (`getApplicationVersionAsFloat` >= 2011)
catch(eval(renderWindowSaveImageCallback ($renderPanel, $renderedFilename, $format)));
else
renderWindowSaveImageCallback ($renderPanel, $renderedFilename, $format);
}
}
}
NextDesign
06-09-2011, 05:48 AM
Why are you changing the texture node each iteration? Why not just change the texture's path? It'll be faster.
Falott
06-09-2011, 05:05 PM
ah, it´s simply because each tileTexture isn´t tiled 1:1. about 80% of all textures have a tiling of 2,83 : 2,65 and so on. another advantage of this method is that I can add an extra attribute "realTextureName" to the fileNodes. this attribute could be called then to add another string to the rendered image files and the destination folder. because names like texture_1 to texture_250 is somewhat meaningless.
NextDesign
07-09-2011, 02:50 AM
Ah, alright, awesome. Glad it worked out for you!
Falott
07-09-2011, 06:50 PM
thanks to you! Couldn´t have done that alone. this correspondence with you really encouraged me to learn MEL now. I am used to fighting with mel script since years now but I never was able to wrap my brain around it. this is the first time for me that getting into mel was kind of fun and not just a pure pain in the ass.
You Rock Dude!
NextDesign
08-09-2011, 01:57 AM
No problem mate, glad to help :)
MEL scripting is definitely a useful skill, not just for TDs, but artists as well.
Copyright © 1999-2021 SimplyMaya | Forum Copyright © 2021 vBS, Inc. All rights reserved