Channels Extractor

Download channelSplit.py

python, nuke

This little script list all the channels within a Nuke node and extract them in different noOp nodes, tihs script has been an occasion to write a tutorial available on 3dbunk


Full code here ;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
node, chans = nuke.selectedNode(), set()
# We get the correct file's name
filename = nuke.tcl('knob [topnode %s].file' % node.name())
# We split it to have only tail, and again to get a good part of the file's name
nicename = '_'.join(filename.split('/')[-1].split('_')[:-1])

# Getting channels inside the node
for chan in node.channels():
    chans.add(chan.split('.')[0]) # add is equivalent to append for a set
# Setting correct start place
x, y = node.xpos() - (len(chans) - 1) * 50, node.ypos() + 100

for i, chan in enumerate(chans):
    base_name = '%s_%s' % (nicename, chan)
    # Creating Shuffle node
    shuffle_node = nuke.nodes.Shuffle(name='SHF_%s' % base_name, inputs=[node])
    shuffle_node['in'].setValue(chan) # defining 'in' attribute
    shuffle_node['postage_stamp'].setValue(True)
    shuffle_node['hide_input'].setValue(True)
    # We move our node to the correct position
    shuffle_node['xpos'].setValue(x)
    shuffle_node['ypos'].setValue(y)
    x += 100
    # Creating Remove node
    remove_node = nuke.nodes.Remove(name='REM_%s' % base_name,
                                    inputs=[shuffle_node])
    remove_node['operation'].setValue('keep') # defining Remove to 'keep'
    remove_node['channels'].setValue('rgb') # we keep only 'rgb'
    # Creating Dot node
    dot_node = nuke.nodes.Dot(name='DOT_%s' % base_name, inputs=[remove_node])
    dot_node['label'].setValue(chan) # defining label
    dot_node['hide_input'].setValue(True)
    # moving our Dot node to the correct position
    dot_node['xpos'].setValue(shuffle_node.xpos() + 35)
    dot_node['ypos'].setValue(shuffle_node.ypos() + 100)
    dot_node['note_font_color'].setValue(4286779903)

If you have any questions... =)