View Full Version : Prerender Postrender MEL ??

05 May 2005, 04:52 PM
Hello people,

need some help.. SOS !! :sad:

what i have is this: Have a scene where my character has a blinn shader assigned to it. And one loop of faces have a lambert (glow color - yello) applied to it.

my question : is there a way to render the character as is (in layer one) and a "only-glow" applied poly faces render into a separate layer (layer two) , in one rendering go ??

I wrote a small scipt - kinda PreRender MEL : which would fetch all the names of the faces with the glow lambert applied on. and store them all to a text file, then apply the character shader to these faces and then render the scene - giving me a as is render layer.

Then a PostRender MEL in which i make a new Use Background shader, select all the polygons in a scene and apply the usebg shader and then read that text file, and reapply the glow-shader to these faces and then launch a new render to give me a second layer.

but the problem i found was in batch mode, since the scripts use hypershade commands, these are ignored.:eek: And when i open maya and say render current frame with the respective commands in Pre-render and post-render MEL boxes, it works.. but when i hit batch render button these scripts are not fired !! ?? :argh:

i know i'm missing something.. another scratchy thing is,, these scripts are fired on -per-frame basis right ?? anyone, has AANNNNYYY idea about how to go about this , would help alot. I have more than 100 scenes to be rendered. So thought getting this to work will save alot of time.. instead of rendering as is and then usebg render again !! :eek:

is there a way to say to maya to treat a particular shader to be treated as a "pass" ?? :rolleyes:


05 May 2005, 06:36 AM
hello people..

no one with any ideas ?

need help on this badly..

i came across this.. the script node > with the Execute ON : "Software Render" option.. here in the before command, i put my DoPreRender() and in the after i put DoPostRender() functions.. and when i hit the render single frame button, this executes these two..

but they dont get fired when i hit the batchRender ?? is the batchrender immune to the scriptNodes toooo ?? anyone have any idea about this ??? in David stripnis's book,in the chapter "Rendertime Smoothing" he used this scriptnode method..

the help doc states: if the Execute on : Software render is set, the before and after commands will be fired on and after software render ..but on batch render it doesnt fire ??

pls.. helppp ! :rolleyes:

05 May 2005, 07:19 AM
Cant really help you, but here are two tracks:
- Are the pre and post render scripts at the right place in the project directory?
- I know hypershade command depends on AW scripts which are maybe disactivated at batch rendering. You should use other fucntions that are compiled in Maya (like assignSG I believe)
- Are scripts really need in your project?

05 May 2005, 07:53 AM
Hi Nicool,

thanx forthe reply..

and yes, the DoPreRender() and DoPostRender() functions are all there in the respective scripts in the project folder.. i testedit , in the script editor, when i choose the script node i created , there is a test script buton, and when i use it, the scripts are fired...

about the alternative commands, i shall check the docs again...

actually i need this done as i have more than 100 scenes to be rendered..and if i can do it through this scripting thing will save me alot of time, setting up the scenes manually and launching a second render..


05 May 2005, 08:55 AM
can't you directly write alias? should work otherwise there is almost no need for something like that.

good luck..I'm intersted in it too since i probably will get my self into those sort of thing pretty soon.


05 May 2005, 09:53 AM
hi thematt,

thanx for the reply and i dont exactly know which place to ask this question at alias. have only a bronze membership at alias !

anyone one help me clarify this point ? is the batchrender blind to such pre / post render mel and scriptnodes ??


05 May 2005, 02:42 PM
yes no luck wit a bronze membership..PM me maybe we could work something out. ;)


05 May 2005, 01:18 AM
no, batch render is not immune to pre- and post-render commands, but if you use commands that get data from the maya interface windows could make it fail. try to open the scene in batch mode from a console (command prompt) and run the scripts there to see if thery give no errors. if they do, i think you must rewrite the scripts without using commands related to hypershade, or something.

05 May 2005, 01:33 AM
your commands won't get passed in a batch render for the reason that batch rendering is a windows command (command prompt issued). What you need to do is load in the scripts via either expressions or scriptNodes (avoid SN's if possible) or just render things off in layers (passes).

05 May 2005, 10:33 AM
the batchrender command exists in mel, and the post render scripts really work with it, i tried it. i made a cube, then smoothed it. now i applied setAttr "polySmoothFace1.divisions" 0;
to set pre render mel i wrote setAttr -type "string" defaultRenderGlobals.preRenderMel "setAttr polySmoothFace1.dv 3;";
and for postrender setAttr -type "string" defaultRenderGlobals.postRenderMel "setAttr polySmoothFace1.dv 0;";
. with this command: batchRender perspShape;
it rendered me a ball (// Result: Percentage of rendering done: 100 (/mnt/share/Maya_Work/images/cub/untitled.jpg) //

05 May 2005, 11:54 AM
thank you epemeros & MEL,

thanx verymuch indeed.

well, yes, i have tried and it worked to smooth the cubes like you said ..

but i have some 20 lines of code in pre and 15 lines in post render MEL file .. which have to be executed..

but yes, i have learnt that any hydershade related commands r ignored in batch mode.. but i have been trying to find alternate commands. I need them to replace these lines which i have in my script:

1) hyperShade -objects glowshader; // will store these in a text file....
2) hyperShade -assign cshader; // glow faces get assigned this cshader
3) shadingNode -asShader useBackground; // create a new usebg shader
4) hyperShade -assign usebg; // this in post render mel, will assign all objects the usebg shader
5) hyperShade -assign glowshader; // after reading from text file , to these faces, assign back my glowshader

can anyone point me as to how i can replace these 5 hypershade commands ?

and i the reason i use a script node (with execute on: set to : software render) is because i want the pre script to be launched before the Software Render starts and post script after it finishes the render and from the post mel , i want to launch the second render too .. by using :

string $mayaFile = `file -query -sn`;
print ($mayaFile+" file will be rendered for the second glow pass");

// after all is done, reder the same file second time...
system("maya -render -im glow -of tif "+"\""+$mayaFile+"\"");

i tried using the command line render like so:
c:\projects\scenes\01> render myScene01.mb -preRender "DoPreRender()" -postRender "DoPostRender()"

where the functions are defined in respective MEL files in my script directory. One more thing, these pre/post render mel get fired before and after every frame render. I want to fire my scripts before the SOFTWARE RENDER(as a whole) is launched and after.

right now am rendering it in two separate files / passes . But i have some where around 200 files.. so would be great to save time on this !!


05 May 2005, 08:13 AM
hello people...,

ahaa !! The script node and pre/post render mel dont get fired from the interface !! thanx for helping me out thematt!!! I am sharing your help here because i hope other ppl, could also share some information on this..

thematt :
Hi you will be happy to know that i had an answer from it is.

alias wrote:
It appear to be the case,it will not run when you start a batch render from within the interface. It does appear to work when you render from the command line using mayabatch."

so to answer your question you're right it doesn't work from the interface, now try to do it in batch mode with the comand line. .....

well from what I understand it should just work the way it is now in batch mode, meaning that you just plug the name of you scene into a bat file after you've setup your renderglobal correctly.

something like render myscene.mb You can do the right click on your scene on windows and do a render see if it work that way.

I don't even know if that issue can be overcome with the api, since it's obviously the core of the batchcommand that is buggy. I post what they have said, they didn't say more.
But if it can be render in batch it's not a problem right. :) and they won't do nothing for it.
because most people render in batch anyway (myself include)


so i guess i have to replace the hypershade commands with sets commands. One small doubt..

when i want to query a shader's shading group , i'm using "listConnections glowshader" .I store this in an array and then fetch the name of this SG using : string $glowshaderSG[]=`listConnections glowshader`;
sets -e -forceElement $shadersgss[2]; // ==> hyperShade -assign glowshader;

Is there any other way to find out the shader's shading group ?


05 May 2005, 02:26 AM
i think you could improve the listing of SG with listConnections -t "shadingEngine" myShader; to return only the shading group connections. im not used to shading networks, but in case the SG nodes may plug also to the imputs of materials, but you want to list only the SG in output of the materials, you may improve again as: listConnections -d 1 -s 0 -t "shadingEngine" myShader; ,to return only the destination connections (on the right in hypergraph).
a command to assign directly the material without specifying its shading group to an object is: assignSG myMaterial myShape; . this works in maya 6.5, dunno in earlier versions.

05 May 2005, 12:57 PM
thanx ephemeros,

listConnections thing does work. and returns only the SG !! thanx a lot and yes, the assignSG command doesnt work in maya 6.0 (says cannot find procedure) i think thats a new addition in 6.5 ??

and would like to ask all people out here. how do people in your studios do this ?? how do you setup scenes to render out glow objects to separate layers ?

and have come across the wierd problem of camera clip planes too !! our shots when rendered, produce alot of mesh artifacts (when 2 objects kinda overlap each other) i'm using the following to find and edit them:

string $camsel[]=`ls -sl`;
float $clipplanesncp=`viewClipPlane -q -ncp $camsel[0]`;
float $clipplanesfcp=`viewClipPlane -q -fcp $camsel[0]`;
setAttr ($camsel[0]+".nearClipPlane") $clipplanesncp;
setAttr ($camsel[0]+".farClipPlane") $clipplanesfcp;

works in some shot and not in others. any light on this would be great..

CGTalk Moderation
05 May 2005, 12:57 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.