Ruby: Submit Apple Shake Scripts for Batch Render
A quick-n-dirty Ruby script that takes all the Shake scripts in a given folder, checks to make sure they are all set on maximum quality e.g "Base" and then submits them for render.
#! /usr/bin/env ruby require 'pp' class Fixnum def pad(n) x = self.to_s if x.length < n pad = "0"*(n - x.length) x.insert(0,pad) else x end end end def render(filepath,last_frame) IO.popen("shake -v xml -exec #{filepath} -t 1-#{last_frame}x1", 'r+') end def get_last_frame(file_path) last_frame = File.open(file_path).grep(/SetTimeRange/).to_s.scan(/\d{2,6}/).first.to_i end def get_output_file(file_path) out_file = File.open(file_path).grep(/FileOut/).first.gsub(/\"/,"").split(",")[1].lstrip end def get_quality(file_path) quality = File.open(file_path).grep(/SetUseProxy/).first.match(/\".+\"/).to_a.first end # Get location of scripts $renderQ = {} puts "Where are the scripts?" $TARGET = gets.rstrip $TARGET << "/" if $TARGET !~ /\/$/ $script_list = %x| ls #{$TARGET}*.shk |.split("\n") # Only files with *.shk extension # Replace whitespace (if present) in filenames with underscores $script_list.map! do |f| new_name = f.gsub(/\s/,'_') unless f == new_name puts "Renaming #{f} --> #{new_name}" File.rename(f,new_name) end new_name end # Make sure all renders are full-resolution $script_list.each do |f| file,path,filename = File.open(f), File.dirname(f), File.basename(f).split(/\./) unless file.read.grep(/SetUseProxy/).first =~ /Base/ new_file = File.open(f).read.gsub!(/^SetUseProxy.+;$/,'SetUseProxy("Base");') File.open(f,'w') { |f| f.puts new_file } end end # Get render info on scripts $script_list.each do |f| outfile = get_output_file(f) last_frame = get_last_frame(f) quality = get_quality(f) $renderQ[f] = [last_frame,quality,outfile] end # Print report puts "\n---------| RENDER SCRIPT -- FRAME COUNT -- OUTPUT FILE |---------\n" $renderQ.sort.each { |k,v| puts "#{k} -- #{v.first} --> #{v.last} | #{v[1]}" } puts "---------------------------------------------------" puts "\nPress Enter to continue with render, or force exit." gets # Render $renderQ.each { |k,v| render(k,v.first) }