Macha Posted May 19, 2011 Share Posted May 19, 2011 (edited) Should be simple but I don't know much about batch scripting On Windows, I want to convert a folder with randomly named (some of the sequences, some not) images to rat with the same name but no numbers at the end. For example: bla_3.hrd bla_2.hdr bla_-1.hdr gthg.hrd dumdeedum.txt should become something like bla_3_t.rat bla_2_t.rat bla_-1_t.rat gthg.rat How do I go about that? Edited May 19, 2011 by Macha Quote Link to comment Share on other sites More sharing options...
ikarus Posted May 19, 2011 Share Posted May 19, 2011 i would get your hands on adobe bridge it has a really nice built in batch/sequence renaming tool (since you're in windows) Quote Link to comment Share on other sites More sharing options...
petz Posted May 19, 2011 Share Posted May 19, 2011 for %i in (*.*) do iconvert %i %~ni.rat hth. petz 1 Quote Link to comment Share on other sites More sharing options...
Macha Posted May 19, 2011 Author Share Posted May 19, 2011 Thanks Petz. I'm also embarrassed now. I should really learn that one day. Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted May 19, 2011 Share Posted May 19, 2011 (edited) I wrote a little PowerShell script for this, take a look. Open it in any text editor, and edit first 3 variables. The only thing you need to do is to figure it out, how to run PowerShell scripts There is a permission issue. It's easy to fix... link convertRAT.rar Edited May 19, 2011 by Stalkerx777 Quote Link to comment Share on other sites More sharing options...
lukeiamyourfather Posted May 19, 2011 Share Posted May 19, 2011 If you're more familiar with other languages or environments those can be used too. For example Cygwin or Python. Quote Link to comment Share on other sites More sharing options...
Green-Man Posted May 19, 2011 Share Posted May 19, 2011 For such purposes I use simple Shelf Tool with python code like this: from os import listdir,path,system,environ root = environ["HIP"]+"/textures" root = "d:/imgs" for file in listdir(root): file = path.join(root,file) system("iconvert "+file+" "+file[:-3]+"rat") It's easy to modify the root folder with images or expression for filenames. Quote Link to comment Share on other sites More sharing options...
Ole Posted May 19, 2011 Share Posted May 19, 2011 Here is my shelf script for batch-converting images from within Houdini: import hou import os iconvert = hou.houdiniPath()[3] + '/' + "iconvert.exe" folder = hou.ui.selectFile(title='Images Folder') files = os.listdir(folder) dot = "." extension = "rat" exts = ('.exr', '.jpg', '.tga', '.png','.tif', '.hdr') def rat_folder(): for file in files: file_ext = file[-4:] if file_ext in exts: export = iconvert + ' ' + '"' + folder + file + '"' + ' ' + '"' + folder + file[:-4] + dot + extension + '"' exists = os.path.exists(folder + file[:-4] + dot + extension) if exists is True: status = "File exists. Skipping..." else: os.system(export) status = "Success!" print "----------------------------------------------" print "RAT FOLDER STATUS: " + status print "original=" + folder + file print "new=" + folder + file[:-4] + dot + extension print "----------------------------------------------" if folder != '': safety = hou.ui.displayMessage("Are you sure you want to convert all images in " + folder + " ?", buttons=('Yes', 'No')) if safety == 0 and folder != '': rat_folder() Just paste it into a shelf button. When you press the button, a dialogue will appear that asks for the path. Just select the folder and not any file and press Accept. I have a second button that runs gconvert with extension = "bgeo" for batch object conversions. 1 Quote Link to comment Share on other sites More sharing options...
Green-Man Posted May 19, 2011 Share Posted May 19, 2011 It looks like better real soltion Thanks for listing. Quote Link to comment Share on other sites More sharing options...
Erik_JE Posted May 19, 2011 Share Posted May 19, 2011 http://www.sidefx.com/index.php?option=com_wrapper&Itemid=8 And here is mine. Quote Link to comment Share on other sites More sharing options...
Mykolas Posted May 12, 2015 Share Posted May 12, 2015 Here is my shelf script for batch-converting images from within Houdini: import hou import os iconvert = hou.houdiniPath()[3] + '/' + "iconvert.exe" folder = hou.ui.selectFile(title='Images Folder') files = os.listdir(folder) dot = "." extension = "rat" exts = ('.exr', '.jpg', '.tga', '.png','.tif', '.hdr') def rat_folder(): for file in files: file_ext = file[-4:] if file_ext in exts: export = iconvert + ' ' + '"' + folder + file + '"' + ' ' + '"' + folder + file[:-4] + dot + extension + '"' exists = os.path.exists(folder + file[:-4] + dot + extension) if exists is True: status = "File exists. Skipping..." else: os.system(export) status = "Success!" print "----------------------------------------------" print "RAT FOLDER STATUS: " + status print "original=" + folder + file print "new=" + folder + file[:-4] + dot + extension print "----------------------------------------------" if folder != '': safety = hou.ui.displayMessage("Are you sure you want to convert all images in " + folder + " ?", buttons=('Yes', 'No')) if safety == 0 and folder != '': rat_folder() Just paste it into a shelf button. When you press the button, a dialogue will appear that asks for the path. Just select the folder and not any file and press Accept. I have a second button that runs gconvert with extension = "bgeo" for batch object conversions. I've modified your script a little bit to accept files with extensions wich are longer or shorter then three symbols (ex. *.tx or *.tiff) import hou import os iconvert = hou.houdiniPath()[3] + '/' + "iconvert.exe" folder = hou.ui.selectFile(title='Images Folder') files = os.listdir(folder) dot = "." extension = "rat" exts = ('.exr', '.jpg', '.tga', '.png','.tif', '.hdr', '.tx') def rat_folder(): for file in files: file_ext = os.path.splitext(file)[1] if file_ext in exts: export = iconvert + ' ' + '"' + folder + file + '"' + ' ' + '"' + folder + os.path.splitext(file)[0] + dot + extension + '"' exists = os.path.exists(folder + os.path.splitext(file)[0] + dot + extension) if exists is True: status = "File exists. Skipping..." else: os.system(export) status = "Success!" print "----------------------------------------------" print "RAT FOLDER STATUS: " + status print "original=" + folder + file print "new=" + folder + file[:-4] + dot + extension print "----------------------------------------------" if folder != '': safety = hou.ui.displayMessage("Are you sure you want to convert all images in " + folder + " ?", buttons=('Yes', 'No')) if safety == 0 and folder != '': rat_folder() Quote Link to comment Share on other sites More sharing options...
odcs Posted March 4, 2016 Share Posted March 4, 2016 I was trying to get this work on linux, but failed miserably, what should be changed if need to run on linux?Please help. Thanks I've modified your script a little bit to accept files with extensions wich are longer or shorter then three symbols (ex. *.tx or *.tiff) Quote Link to comment Share on other sites More sharing options...
Alexander Weide Posted August 31, 2017 Share Posted August 31, 2017 I changed the script to work on Linux. THANKS to Ole You only need to change the Path to your Houdini Linux Install(iconvert = "/opt/hfs16.0.600/bin/iconvert-bin") import hou import os #the script converts all files in the same directory like your file selection iconvert = "/opt/hfs16.0.600/bin/iconvert-bin" file = hou.ui.selectFile(title="Image Selection") folder = os.path.dirname(file)+"/" files = os.listdir(folder) dot = "." extension = "rat" exts = ('.exr', '.jpg', '.tga', '.png','.tif', '.hdr') def rat_folder(): for file in files: file_ext = file[-4:] if file_ext in exts: export = iconvert + ' ' + '"' + folder + file + '"' + ' ' + '"' + folder + file[:-4] + dot + extension + '"' exists = os.path.exists(folder + file[:-4] + dot + extension) if exists is True: status = "File exists. Skipping..." else: os.system(export) status = "Success!" print "----------------------------------------------" print "RAT FOLDER STATUS: " + status print "original=" + folder + file print "new=" + folder + file[:-4] + dot + extension print "----------------------------------------------" if folder != '': safety = hou.ui.displayMessage("Are you sure you want to convert all images in " + folder + " ?", buttons=('Yes', 'No')) if safety == 0 and folder != '': rat_folder() Quote Link to comment Share on other sites More sharing options...
Alexander Weide Posted September 3, 2017 Share Posted September 3, 2017 Update: i managed to make it running (hopefully) on all Operating systems not just Linux. Thanks to Symek and Legomyrstan import hou import os, sys #the script converts all files in the same directory like your file selection iconvert = hou.expandString("$HFS"+"/bin/"+"iconvert") #iconvert = "/opt/hfs16.0.600/bin/iconvert-bin" file = hou.ui.selectFile(title="Image Selection") folder = os.path.dirname(file)+"/" files = os.listdir(folder) dot = "." extension = "rat" exts = ('.exr', '.jpg', '.tga', '.png','.tif', '.hdr') def rat_folder(): for file in files: file_ext = file[-4:] if file_ext in exts: export = iconvert + ' ' + '"' + folder + file + '"' + ' ' + '"' + folder + file[:-4] + dot + extension + '"' exists = os.path.exists(folder + file[:-4] + dot + extension) if exists is True: status = "File exists. Skipping..." else: os.system(export) status = "Success!" print "----------------------------------------------" print "RAT FOLDER STATUS: " + status print "original=" + folder + file print "new=" + folder + file[:-4] + dot + extension print "----------------------------------------------" if folder != '': safety = hou.ui.displayMessage("Are you sure you want to convert all images in " + folder + " ?", buttons=('Yes', 'No')) if safety == 0 and folder != '': rat_folder() Quote Link to comment Share on other sites More sharing options...
Ippokratis Posted September 23, 2019 Share Posted September 23, 2019 Hi, Many thanks for sharing your code. None of the above versions works on Win 10, Houdini 17.5.258. I have coded the snippet below that (hopefully) solves several version & OS related problems. I checked it on Windows only and works. Hope you can find it useful, give me some feedback if you encounter problems. import hou, os iconvert = hou.getenv("HFS") + "/bin/" +"iconvert.exe" iconvert = os.path.abspath(iconvert) folder = hou.ui.selectFile(title='Images Folder', file_type=hou.fileType.Directory) folder = hou.expandString(folder) files = os.listdir(folder) dot = "." extension = "rat" exts = ('.exr', '.jpg', '.tga', '.png','.tif', '.hdr') def rat_folder(): for file in files: realName = os.path.abspath( folder + file) file_ext = realName[-4:] if file_ext in exts: export = iconvert + " " + realName + " " + realName[:-4] + dot + extension exists = os.path.exists(realName[:-4] + dot + extension) if exists is True: status = "File exists. Skipping..." else: os.system(export) status = "Success!" print "----------------------------------------------" print "RAT FOLDER STATUS: " + status print "original = " + realName print "new =" + realName[:-4] + dot + extension print "----------------------------------------------" if folder != '': safety = hou.ui.displayMessage("Are you sure you want to convert all images in " + folder + " ?", buttons=('Yes', 'No')) if safety == 0 and folder != '': rat_folder() Kind regards, Ippokratis 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.