Skip to content

Instantly share code, notes, and snippets.

@melMass

melMass/README.md

Last active Apr 2, 2021
Embed
What would you like to do?
Nuke batch scripts

Batch Nuke

My collection of batch scripts for Nuke.

Generate SM

With the generate_smart_vector function you can batch load a video folder and generate the appropriate Smart Vectors for each of them.

# I use the interactive version but you can easily parse cli arguments and use execture (-x) instead
nuke -t
import generate_smart_vector from batch
generate_smart_vector("path/to/my/videos")
import nuke
import os
here = os.path.realpath(os.path.dirname(__file__))
def generate_smart_vectors(folder_path, suffix=".mov",detail=0.3):
path = folder_path
sm = os.path.join(path,"SmartVectors")
# Onl
files = [x for x in os.listdir(path) if x.endswith(suffix)]
nuke.scriptOpen(os.path.join(here,"./sm_template.nk"))
readnode = nuke.toNode("Read")
writenode = nuke.toNode("Write")
# Sets the detail value
nuke.toNode("SmartVector")["vectorDetailReg"].setValue(detail)
for file in files:
# replace the read (using fromUserText to call the callbacks)
readnode["file"].fromUserText(os.path.join(path,file))
# get the range
end = int(readnode['last'].getValue())
current_name = os.path.split(file)[1].split(".")[0]
current_folder = os.path.join(sm,current_name)
# set the output path
writenode["file"].setValue(os.path.join(current_folder,current_name + "####.exr"))
# render
nuke.execute(writenode,1,end)
# save as
nuke.scriptSave(os.path.join(current_folder,current_name + ".nk"))
Root {
inputs 0
name sm_template.nk
}
Read {
inputs 0
file_type mov
file "xxx.mov"
format "4340 2650 0 0 4340 2650 1 "
last 71
origlast 71
origset true
version 1
mov32_codec {{0} "Apple ProRes 4444 (appl - ap4h)"}
mov32_pixel_format {{0} "default (RGBA 16-bit (b64a))" "RGBA 8-bit" "RGBA 16-bit (b64a)" "YCbCrA 8-bit 444 (v408)" "YCbCrA 8-bit 444 Biased (r408)" "YCbCrA 32-bit 444 Float (r4fl)" "YCbCr 16-bit 444 (y416)"}
name Read
xpos -40
ypos -261
}
set N164ca000 [stack 0]
Viewer {
frame 1
frame_range 1-12
name Viewer1
xpos -40
ypos -9
}
push $N164ca000
SmartVector {
name SmartVector
xpos 70
ypos -135
}
Write {
channels all
file "####.exr"
file_type exr
metadata "all metadata except input/*"
interleave channels
first_part rgba
write_full_layer_names true
create_directories true
version 24
name Write
xpos 70
ypos -63
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment