Batch Render Scripting
This is a script that takes previously generated rib files and renders them in prman to .exr files.
​
The instructions to do so are as follows-
​
1. Locate the folder where the .rib files are sitting.
2. List off the .rib file extensions so they are able to be recognized. - This is key so that the script can run through each individual .rib separately.
3. Search the directory of the folder for the files. - This allows access to grab each file extension.
4. Run prman to render .rib files.
​
The code for this operation is as follows-
​
import os
import os.path
import inspect
import re
import glob
fullpath = inspect.getframeinfo(inspect.currentframe()).filename
dirpath = os.path.dirname(os.path.abspath(fullpath))
glob_pattern = os.path.join(dirpath, '*.rib')
paths = glob.glob(glob_pattern)
ext = re.compile(r'(\w+)[._]+(\d+)[._]+rib')
extensions = []
for s in paths:
found_it = re.search(ext, s)
if found_it:
extensions.append('%s' % found_it.group(2))
doit = ('prman -cwd "%s" -t:all -progress "%s"' % (dirpath, s))
os.system(doit)
​
Once again, once the .py script and the executable script are in the desired folder of .ribs, double clicking will execute the python script.
​
python batchRender. py
read
​
And for windows, it will be a .bat file that reads -
​
C:/python27/python batchRender.py
pause
​
Another version of this script that creates an executable file in the project directory is as follows. This script gives the user more control and places the executable file in the root of the project directory, rather than having to go into the .rib folder. -
​
# Place this script in ribs folder.
import inspect
import os.path
import os
import glob
# This locates where the .py script is.
fullpath = inspect.getframeinfo(inspect.currentframe()).filename
ribspath = os.path.dirname(os.path.abspath(fullpath))
scriptname = os.path.basename(fullpath)
print('"%s" is located in "%s".' % (scriptname, ribspath))
#This goes up 4 levels into the parent directory of the .rib files.
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)
print('"%s" is the project' % project_dir)
# These are a list of all the flags used in the terminal turned into
# strings.
rmantree_str = '' #Depending on OS
if os.name == 'nt':
rmantree_str = '"C:\Program Files\Pixar\RenderManProServer-22.0\bin\prman"'
batch_script_path = os.path.join(project_dir, 'do_batch_render.bat')
else:
rmantree_str = '/opt/pixar/RenderManProServer-22.3/bin/prman'
batch_script_path = os.path.join(project_dir, 'do_batch_render')
prman = '%s ' % rmantree_str
cwd = '-cwd "% s" ' % project_dir
t_str = '-t:all '
progress = '-progress '
# Get a listing of all the .rib files.
glob_pattern = os.path.join(ribspath, '*.rib')
ribs = glob.glob(glob_pattern)
# Writes out batch script in terminal.
f = open(batch_script_path, 'w')
for rib in ribs: #Will execute for each .rib file.
f.write(prman)
f.write(cwd)
f.write(t_str)
f.write(progress)
f.write('"%s"' % rib)
f.write('\n') #signals new line
f.close()
The difference in this script is that there is more control over how the render is run. Also, the script will recognize which OS system it is operating on, and will create an executable script for that specific system.
​
