convert images folder to .rat files?

   3336   4   1
User Avatar
Member
99 posts
Joined: Nov. 2018
Offline
Hi how i can convert all images file inside a folder to a mipmap files for karma? maybe with pdg its possible?
Edited by Piledriver - Sept. 8, 2022 14:10:30
User Avatar
Member
152 posts
Joined: June 2020
Offline
There's probably a way to do this in directly in command line but I'm not good with the syntax so I wrote a Python script to do it for me (I'm also not good with Python).

You can run this directly from Houdini from the Python Source Editor and it should find the imaketx executable.
Or you can change the cmd variable to point directly to a different .exe like maketx from Arnold or txmake from Pixar and fiddle with the command arguments.

import os
import subprocess


folder = "<path_to_folder_with_your_textures>"
out_ext = ".rat" # the output file extension
in_ext = ".exr" # the extension of the files to convert
cmd = "imaketx"

# only convert files with in_ext extension
files = (file for file in os.listdir(folder) if os.path.isfile(os.path.join(folder, file)) and in_ext in file)

for i in files:
    name, ext = os.path.splitext(i)
    infile = folder + i
    outfile = folder + name + out_ext
    
    command = "{} -v -m ocio --format RAT {} {}".format(cmd, infile, outfile)
    output = subprocess.run(command, capture_output=True)
    print(output)
Edited by freshbaked - Sept. 8, 2022 18:54:35
User Avatar
Member
8177 posts
Joined: Sept. 2011
Offline
Piledriver
Hi how i can convert all images file inside a folder to a mipmap files for karma? maybe with pdg its possible?

yes, it's a fairly simple pdg setup. The generic generator can be used to run a command line program and the file pattern node can be used to glob for input files. It can be a little tricky to get the in file out file set up to work, but when you do pdg wil automatically multi thread the convert process per file.
User Avatar
Member
152 posts
Joined: June 2020
Offline
Hey sweet! I don't use pdg much so I had no idea about the generic generator.

Just a file pattern node and a generic generator with this command:
imaketx -v -m ocio --format RAT `@directory`/`@filename``@extension` `@directory`/`@filename`.rat

Worked like a charm and way faster than my lame python script.

Thanks!
Edited by freshbaked - Sept. 8, 2022 21:06:26
User Avatar
Member
99 posts
Joined: Nov. 2018
Offline
great guys for the answers! thanks
Edited by Piledriver - Sept. 9, 2022 02:47:14
  • Quick Links