Showing posts with label vray vrimg vrimg2exr exr channels canali automatico python. Show all posts
Showing posts with label vray vrimg vrimg2exr exr channels canali automatico python. Show all posts

Tuesday, March 29, 2011

Script per automatizzare il lavoro di VRIMG2EXR

Sono di fretta ma posto questo script che ho fatto in python per estrarre in un colpo solo tutti i canali da un file VRIMG. Per ora è lanciato tramite un batch perchè non sono ferratissimo in python e avevo necessità di farlo funzionare, sono aperto a qualunque miglioramento :)
Funziona da interfaccia per vrimg2exr.exe, ora sono proprio di corsa ma posto il codice perchè lo sto usando in questo momento e lavora da dio.

vrconv.bat:
@echo off
rem VRCONV: automatize vrimg conversion to exr,
rem finding all channels and separing them
rem -------- (C) 2011 Pietro Grandi -----------

rem Put here your ../vrimg2exr.exe complete path to find it
set VRAY2EXR=vrimg2exr.exe

rem Requiring info
%VRAY2EXR% -info %1 > %1.INFO.txt
if errorlevel 1 (goto:error)

rem Generate info file
set VRCONV_FILE=%1.INFO.txt
echo cmd: File has been saved as %VRCONV_FILE%
python vrconv.py %VRCONV_FILE%
goto:eof

:error
echo Some error occurred with %VRAY2EXR%


vrconv.py
import sys
import string
import os

name="vrconv"
info_file=sys.argv[1]
vrimg2exr=os.environ["VRAY2EXR"]

print("{1}: Assuming {0} as info file...".format(info_file, name))
print("{0}: vrimg2exr is located in {1}".format(name, vrimg2exr))
f = open(info_file)
k=0

current=f.readline()
v_channels=[()]

# Isolating info between quotes...
while current :
index=current.find('"')
if index!=-1 :
rev_index=current.find('"',index+1)+1 # +1 is to keep quotes
v_channels.append(current[index:rev_index])
k+=1
current=f.readline()

print("{0}: {1} channels found. Extracting...".format(name, k-1))

filename_vrimg=v_channels[1].strip('"')
filename_basic=filename_vrimg.strip('vrimg')

for i in range(2,k) :
print("{0}: Working on {1} channel".format(name,v_channels[i]))
os.system(vrimg2exr+" "+filename_vrimg+" "+"-channel "+v_channels[i])
filename_new=filename_basic+v_channels[i].strip('"')+".exr"
print("{0}: {1} is now {2}".format(name,filename_basic+"exr",filename_new))
os.rename((filename_basic+"exr"),filename_new)