Batch Render Scripts

This page explains the development of a python script that can batch render a sequence of RenderMan .rib files.

 
 

ALGORITHM FOR BATCH RENDERING

1. Use the inspection module to determine what files we need and the location of the directory.
2. Determine the project directory to which rendering must be relative. (Always the fourth directory previous to the rib directory.)
3. Make the strings that will remain unchanged.
3.1 Make sure the script with work for both Windows and Linux opperating systems.
4. Get a listing of all the .rib files to render.

 

THE CODE - "batch_render.py"

import inspect
import os.path
import os
import glob
  
# 1. Use the inspection module to find out who we are and where we are.
fullpath = inspect.getframeinfo(inspect.currentframe()).filename
ribspath = os.path.dirname(os.path.abspath(fullpath))
scriptname = os.path.basename(fullpath)

  
# 2. Rendering must happen relative to the "project directory" - always the forth grandparent of the ribs directory. 
parent_dir = os.path.dirname(ribspath)
parent_dir = os.path.dirname(parent_dir)
parent_dir = os.path.dirname(parent_dir)
project_dir = os.path.dirname(parent_dir)
  
# 3. Make the strings that will not change.
rmantree_str = '' 
if os.name == 'nt':
    #windows
    #needs "" within '' because of space in directory
    rmantree_str = '"C:\Program Files\Pixar\RenderManProServer-22.3\bin\prman"'
    batch_script_path = os.path.join(project_dir, 'do_batch_render.bat')
else:
    #linux
    rnametree_str = '/opt/Pixar/RenderManProServer-22.3/'
    batch_script_path = os.path.join(project_dir, 'do_batch_render')
  
prman_str = 'rmantree_str '
cwd_str = '-cwd "%s" ' % project_dir
t_str = '-t:all '
progress_str = '-progress '
  
# 4. Get a listing of all the .rib files.
glob_pattern = os.path.join(ribspath, '*.rib')
ribs = glob.glob(glob_pattern)
  
batch_script_path = os.path.join(project_dir, 'do_batch_render')
f = open(batch_script_path, 'w')
  
for rib in ribs:
    f.write(prman_str)
    f.write(cwd_str)
    f.write(t_str)
    f.write(progress_str)
    f.write('"%s"' % rib)
    f.write('\n')
f.close()
 

ALGORITHM FOR BATCH RENDERING SEQUENCES WITH OVER 100 FRAMES

1. Use the inspection module to determine what files we need and the location of the directory.
2. Get a listing of all the .rib files to render.
3. Determine the number of files and the number of groups of 100 frames.
4. Create a list of numbers for the frame range.
5. Create a batch render script that works with both Windows and Linux operating systems.

 

INSTRUCTIONS

1. Place the batch_render_groups.py code into the ribs folder that contains the .rib files that need to be rendered.
2. Execute the script from this location.
3. On Linux double click the file called "run_batch_render_1", on Windows double click the file called "run_batch_render_1.bat". (If more than 100 files need to be rendered, multiple files will be created and numbered in order based on groups. For instance, the first group of 100 files will be labeled "run_batch_render_1" or "run_batch_render_1"; the second group will be labeled "run_batch_render_2" or "run_batch_render_2.bat" and so on and so forth.)

 

THE CODE - "batch_render_groups.py"

import os
import os.path
import glob
import inspect
import re
  
# 1. Use the inspection module to determine what files we need and the location of the directory.
scptpth = inspect.getframeinfo(inspect.currentframe()).filename
dirpath = os.path.dirname(os.path.abspath(scptpth))
projpath = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(dirpath))))
  
# 2. Get a listing of all the .rib files to render.
glob_patt = os.path.join(dirpath, '*.rib')
paths = glob.glob(glob_patt)
paths.sort()
  
# 3. Determine the number of files and the number of groups of 100 frames.
fnum = len(paths)
lnum = (fnum/100)+1
  
# 4. Create a list of numbers for the frame range.
nlist = []
for n in range(0, lnum):
    m = n * 100
    nlist.append(m)
nlist.insert(lnum, fnum)
  
# 5. Create a batch render script that works with both Windows and Linux operating systems.
if os.name == 'posix':
    for n in range(0, lnum):
        out = n+1
        filepath = os.path.join(projpath, 'run_batch_render_%s' % out)
        f = open(filepath, 'w')
    
        for x in range(nlist[0], nlist[1]):
            path = paths[x]
            f.write('prman -cwd "'+projpath+'" -t:all -progress "'+path+'"\n')
        f.write('read\n')
    
        f.close()
    
        nlist.pop(0)
        print ('"run_batch_render_%s" successfully created in project directory' % out)
else:
    for n in range(0, lnum):
        out = n+1
        filepath = os.path.join(projpath, 'run_batch_render_%s.bat' % out)
        f = open(filepath, 'w')
    
        f.write('export RMANTREE=C:\Program Files\Pixar\RenderManProServer-22.0\n')
        for x in range(nlist[0], nlist[1]):
            path = paths[x]
            f.write('"$RMANTREE/bin/prman" -cwd "'+projpath+'" -t:all -progress "'+path+'"\n')
        f.write('pause\n')
    
        f.close()
    
        nlist.pop(0)
        print ('"run_batch_render_%s.bat" successfully created in project directory' % out)
 

PRINTED CONFIRMATION UPON EXECUTION OF THE CODE

When the "batch_render_groups.py" code is executed, there should be a printed confirmation, like in the above image. If there is more than one group, multiple "run_batch_render" files will be created, numbered in order, and listed in the printed con…

When the "batch_render_groups.py" code is executed, there should be a printed confirmation, like in the above image. If there is more than one group, multiple "run_batch_render" files will be created, numbered in order, and listed in the printed confirmation.

 

DISPLAYED CONTENTS OF "run_batch_render_1" FILE

The contents of the "run_batch_render_1" file should appear as it does in the above image.

The contents of the "run_batch_render_1" file should appear as it does in the above image.

 

RUNNING THE "run_batch_render_1" SCRIPT

The above image shows the part of the result of running the "run_batch_render_1" file from the terminal.

The above image shows the part of the result of running the "run_batch_render_1" file from the terminal.

 

RESTRICTIONS

This is meant as an example for the process of batch rendering a sequence of image files. The code assumes that the user wishes to make rendering relative to the fouth previous directory from the rib directory. Depending on the user's personal system and workflow, the user may wish to "jump back" more or less directories. Additionally, this code is tailored to .rib files, but others may wish to use .ass or .ifd files. This code should be use as a starting point and should be tailored to suit the user's needs.