Created
April 16, 2009 13:37
-
-
Save jimmac/96415 to your computer and use it in GitHub Desktop.
watch a directory for blender project files and render the default scene if one appears
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'directory_watcher' | |
require 'ftools' | |
FOLDER = './render-queue' | |
#THREADS = 8 | |
#BLENDER = '/usr/bin/blender' | |
BLENDER = '/Applications/blender/blender.app/Contents/MacOS/blender' | |
def randomFileName (numberOfRandomchars) | |
s = "" | |
numberOfRandomchars.times { s << (65 + rand(26)) } | |
return s | |
end | |
def uniqueDir (dir) | |
return !File.exists?("#{FOLDER}/render/#{dir}") | |
end | |
File.makedirs("#{FOLDER}/render") unless File.exists?("#{FOLDER}/render") | |
dw = DirectoryWatcher.new FOLDER, :glob => '**/*.blend', :pre_load => true | |
dw.interval = 2.0 | |
dw.stable = 2 #making sure the file is fully synced | |
puts "watching #{FOLDER} for Blender project files." | |
dw.add_observer do |*args| | |
args.each do |event| | |
if event.type == :stable | |
outdir = 'RENDER' | |
until uniqueDir(outdir) | |
outdir = randomFileName(5) | |
end | |
cmd = "#{BLENDER} -b #{event.path} -f 1 -o #{FOLDER}/render/#{outdir}/" | |
puts "rendering #{event.path}" | |
system(cmd) #render | |
File.unlink(event.path) #remove the .blend file after rendering | |
end | |
end | |
end | |
dw.start | |
gets # when the user hits "enter" the script will terminate | |
dw.stop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment