Skip to content

Instantly share code, notes, and snippets.

@WesleyE
Last active August 29, 2015 14:23
Show Gist options
  • Save WesleyE/ea815869fd56da221ff9 to your computer and use it in GitHub Desktop.
Save WesleyE/ea815869fd56da221ff9 to your computer and use it in GitHub Desktop.
Transcoding your textures to .rat files. Check http://scripts.wesleyelfring.nl/textures-to-rat/
import os
import glob
import subprocess
def we_startConversion():
#Double check overwrite
if hou.pwd().parm("cbOverwrite").eval() == 1:
if hou.ui.displayMessage("Are you sure you want to overwrite RAT files?", buttons=("Yes", "No")) == 1:
hou.pwd().parm("cbOverwrite").set(0)
doOverwrite = hou.pwd().parm("cbOverwrite").eval()
doWholeDir = hou.pwd().parm("cbWholeDir").eval()
if doWholeDir == 0:
#If the user only selected the one file
outputDir = os.path.dirname(os.path.realpath(hou.pwd().parm("firstImage").eval()))
fileName = os.path.splitext(os.path.realpath(hou.pwd().parm("firstImage").eval()))[0]
if os.path.exists(fileName + ".rat"):
if doOverwrite == 1:
subprocess.call("iconvert \"" + os.path.realpath(hou.pwd().parm("firstImage").eval()) + "\" \"" + fileName + ".rat\"", shell=True)
else:
subprocess.call("iconvert \"" + os.path.realpath(hou.pwd().parm("firstImage").eval()) + "\" \"" + fileName + ".rat\"", shell=True)
hou.ui.displayMessage("Conversion complete", buttons=("Ok",))
else:
#If the user selected the whole dir
#Setup file names to convert
outputDir = os.path.dirname(os.path.realpath(hou.pwd().parm("firstImage").eval()))
types = ('*.pic', '*.pic.gz', '*.pic.Z', '*.gif', '*.jpg', '*.png', '*.tiff', '*.tif', '*.tga', '*.jpeg')
files_grabbed = []
for files in types:
files_grabbed.extend(glob.glob(outputDir + os.sep + files))
#Setup long operation
num_tasks = len(files_grabbed)
with hou.InterruptableOperation(
"Converting images", open_interrupt_dialog=True) as operation:
i = 0
for image in files_grabbed:
fileName = os.path.splitext(os.path.realpath(image))[0]
print "iconvert \"" + image + "\" \"" + fileName + ".rat\""
if os.path.exists(fileName + ".rat"):
if doOverwrite == 1:
subprocess.call("iconvert \"" + image + "\" \"" + fileName + ".rat\"", shell=True)
else:
subprocess.call("iconvert \"" + image + "\" \"" + fileName + ".rat\"", shell=True)
i = i + 1
# Update operation progress.
percent = float(i) / float(num_tasks)
operation.updateProgress(percent)
hou.ui.displayMessage("Conversion complete", buttons=("Ok",))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment