FrameRenderLog - Tutorial & Script |
MAXScript Release 0.1 Tutorial and Source for 3ds max 4 and higher (05/03/2003)Code by Borislav PetrovOnline Tutorial Text Last Edited on 05/03/2003, 5:00pm CET |
SHORT DESCRIPTION |
FrameRenderLog is a simple callback script to write frame rendering time information to an external file. |
I WANT TO DOWNLOAD THE READY SCRIPT AND SKIP THE TUTORIAL... |
.Click here to get the final script.. |
WHAT DO WE WANT TO ACHIEVE? |
|
1. INITIALIZING THE LOG FILE |
txt1
= "frame_render_log = openFile ((GetDir #Image)+\"/RenderFrames.log\")
mode:\"a\" \n "
txt1 +="if frame_render_log == undefined then frame_render_log = createFile ((GetDir #Image)+\"/RenderFrames.log\") \n" txt1 +="format \"Rendering [%] \n\" rendOutputFileName to:frame_render_log \n" txt1 +="close frame_render_log \n"
callbacks.addScript #PreRender txt1 id:#frame_render_times |
First we will
define a text variable containing the log file initialization code. The variable will be then assigned to a PreRender callback and will be executed every time a new rendering is started. We define a text variable called txt1
containing the callback code. So now we have to check the value and see
if it is undefined or not. Then we will output the text "Rendering
" and the output file name as a starting line for the
following rendering sequence. Finally, we add a close function call to close the FileStream. The resulting string variable txt1 contains
the complete code for the first callback. |
2. STOPPING THE FRAME START TIME |
txt2
= "global frame_rendering_start_time = timestamp()\n"
callbacks.addScript #PreRenderFrame txt2 id:#frame_render_times |
The second callback
code will stop the start frame time.
We define a second text variable called txt2
containing a single line. Then we add the callback script using the #PreRenderFrame
flag. |
3. OUTPUTTING THE FRAME RENDER TIME |
txt3
= "frame_render_log = openFile ((GetDir #Image)+\"/RenderFrames.log\")
mode:\"a\" \n "
txt3 +="format \"Frame Time: % sec. \n\" ((timestamp()-frame_rendering_start_time)/1000.0) to:frame_render_log \n" txt3 +="close frame_render_log \n" callbacks.addScript #PostRenderFrame txt3 id:#frame_render_times |
The last callback
code will stop the end frame time and output it to the external
file.
We define a text variable called txt3. Then we use format to output the frame
time to the file. We close the file after outputting the
line. |
4. DISABLING THE CALLBACKS |
callbacks.removeScripts id:#frame_render_times |
Before defining
the callbacks, we should call the removeScripts function using the
user-defined id name. Adding the scripts without removing existing ones could lead to a large number of identical callbacks executed all at the specified event. This would mean in our case that multiple lines could be outputted for the same frame. The same line will be used in the disabling MacroScript (see below). |
5. DEFINING THE MACROSCRIPTS |
macroScript
enableFrameLog category:"Bobo_s Tools"
( )
macroScript disableFrameLog category:"Bobo_s Tools" ( ) |
We will need two
MacroScripts - the one called enableFrameLog will define the code, remove
existing and add the new callback scripts. The second will only remove any callback scripts by id. If there are none, nothing will happen. See below for the complete source code. |
COMPLETE SOURCE: |
macroScript
enableFrameLog category:"Bobo_s Tools"
( txt1 = "frame_render_log = openFile ((GetDir #Image)+\"/RenderFrames.log\") mode:\"a\" \n " txt1 +="if frame_render_log == undefined then frame_render_log = createFile ((GetDir #Image)+\"/RenderFrames.log\") \n" txt1 +="format \"Rendering [%] \n\" rendOutputFileName to:frame_render_log \n" txt1 +="close frame_render_log \n"
txt2 = "global frame_rendering_start_time = timestamp()\n"
txt3 = "frame_render_log = openFile ((GetDir #Image)+\"/RenderFrames.log\") mode:\"a\" \n " txt3 +="format \"Frame Time: % sec. \n\" ((timestamp()-frame_rendering_start_time)/1000.0) to:frame_render_log \n" txt3 +="close frame_render_log \n"
callbacks.removeScripts id:#frame_render_times callbacks.addScript #PreRender txt1 id:#frame_render_times callbacks.addScript #PreRenderFrame txt2 id:#frame_render_times callbacks.addScript #PostRenderFrame txt3 id:#frame_render_times ) macroScript disableFrameLog category:"Bobo_s Tools" ( callbacks.removeScripts id:#frame_render_times ) |