Skip to content

Instantly share code, notes, and snippets.

@bdancer
Last active August 29, 2015 14:20
Show Gist options
  • Save bdancer/b997a487a0c7586648cd to your computer and use it in GitHub Desktop.
Save bdancer/b997a487a0c7586648cd to your computer and use it in GitHub Desktop.
#
# V-Ray For Blender Batch Render
#
# http://chaosgroup.com
#
# Author: Andrei Izrantcev
# E-Mail: andrei.izrantcev@chaosgroup.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# All Rights Reserved. V-Ray(R) is a registered trademark of Chaos Software.
#
import argparse
import os
import subprocess
import tempfile
temp_render_file = os.path.join(tempfile.gettempdir(), 'batch_temp_render.png')
def render_file(blender_bin, filepath, show_vfb=False, output_dir="", test_mode=False):
print("Rendering: %s..." % filepath)
blender_args = [blender_bin]
# blender_args.append('-d')
blender_args.append('-b')
blender_args.append(filepath)
blender_args.append('--python')
blender_args.append(os.path.join(os.path.dirname(__file__), 'vb30_batch_directory_render.py'))
blender_args.append('--')
if show_vfb:
blender_args.append('--show_vfb')
if output_dir:
blender_args.append('--override_output')
blender_args.append('--output_dir=%s' % output_dir)
print("Starting: %s" % " ".join(blender_args))
if not test_mode:
res = subprocess.call(blender_args)
print("Command exit with: %i" % res)
if __name__ == '__main__':
parser = argparse.ArgumentParser(usage="python3 build.py [options]")
gr = parser.add_argument_group(title="Paths")
gr.add_argument('--blender',
default = "",
help = "Blender binary path",
metavar = 'FILE'
)
gr.add_argument('--dir',
default = os.getcwd(),
help = "Blendfiles directory",
metavar = 'FILE'
)
gr.add_argument('--dir_output',
default = "",
help = "Output directory",
metavar = 'FILE'
)
gr.add_argument('--recursive',
action = 'store_true',
help = "Process subdirectories",
default = False
)
gr = parser.add_argument_group(title="Debug")
gr.add_argument('--test',
action = 'store_true',
default = False
)
gr = parser.add_argument_group(title="Mist")
gr.add_argument('--show_vfb',
action = 'store_true',
default = False
)
args = parser.parse_args()
arg_err = False
if not args.dir:
print("Error: Blend files directory is not specified!")
arg_err = True
if not os.path.exists(args.dir):
print("Error: Blend files directory is not found!")
arg_err = True
if not args.blender:
print("Error: Blender birnary is not specified!")
arg_err = True
if not os.path.exists(args.blender):
print("Error: Blender birnary is not found!")
arg_err = True
if arg_err:
parser.print_help()
else:
print("Blendfile directory: %s" % args.dir)
print("Blender binary: %s" % args.blender)
filelist = []
if args.recursive:
for root, dirs, files in os.walk(args.dir):
for name in files:
if name.endswith(".blend"):
filelist.append(os.path.join(root, name))
else:
for name in os.listdir(args.dir):
if name.endswith(".blend"):
filelist.append(os.path.join(args.dir, name))
for filepath in filelist:
render_file(args.blender, filepath,
show_vfb=args.show_vfb,
output_dir=args.dir_output,
test_mode=args.test
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment