Last active
May 21, 2023 18:29
-
-
Save p2or/caf79eb257ffec24cef1f27b1122f576 to your computer and use it in GitHub Desktop.
Batch Converter #Nuke
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
file_prefix = None # If set to None read node file path is used | |
color_space = None # Read node colorspace "sRGB", "Cineon", "Gamma2.4" ... | |
file_types = ("exr", "jpg") # Set of file types to convert | |
rotate = False # If set to True, another reformat node will be created | |
rotation_props = ("center", "turn") # clockwise: ("flip", "flop", "turn") | |
selection = nuke.selectedNodes() | |
current_node = None | |
for idx, item in enumerate(selection): | |
if item.Class() != "Read": | |
continue | |
path, file = os.path.split(item["file"].value()) | |
if color_space: | |
#print (item['colorspace'].value()) | |
item['colorspace'].setValue(color_space) | |
#print (item['format'].value().width()) | |
current_node = item | |
if rotate: | |
#item.setSelected(True) | |
reformat_node = nuke.createNode("Reformat") | |
reformat_node["type"].setValue("scale") | |
reformat_node["resize"].setValue("none") | |
for prop in rotation_props: | |
reformat_node[prop].setValue("true") | |
reformat_node.setInput(0,item) | |
current_node = reformat_node | |
for f in file_types: | |
#nuke.toNode(current_node.name()) | |
if file_prefix: | |
file_name = "%s-%02d.%s" % (file_prefix, idx+1, f) | |
else: | |
file_name, ext = os.path.splitext(file) | |
file_name = "%s.%s" % (file_name, f) | |
write_path = os.path.join(path, file_name).replace("\\","/") # Windows | |
write_node = nuke.createNode("Write") | |
write_node["file"].setValue(write_path) | |
if f == "jpg": | |
write_node["_jpeg_quality"].setValue("1") | |
write_node.setInput(0,current_node) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment