Controlling the ShuffleCopy through Python

Written by Justin Kirk on .

The shuffleCopy node might be one of the hardest things to grasp for new Nuke users. Throw a bit of python at it and I bet we could confuse even a seasoned user.

Lets try a bit of code and see what we get.

# Creating a new shuffleCopy
shuffle_copy = nuke.nodes.ShuffleCopy(name="test")

# If the new channel doesnt exist, create it
nuke.Layer( 'newLayer', ['red', 'green', 'blue','alpha'] )

# Set the output of the new shuffle coppy to the newly channel created
shuffle_copy['out2'].setValue('newLayer')

# Passing through the rgba from pipe2
shuffle_copy['red'].setValue('red2')
shuffle_copy['green'].setValue('green2')
shuffle_copy['blue'].setValue('blue2')
shuffle_copy['alpha'].setValue('alpha2')

# Passing through the rgba of pipe1 to the new channel via output2
shuffle_copy['red2'].setValue('red')
shuffle_copy['green2'].setValue('green')
shuffle_copy['blue2'].setValue('blue')
shuffle_copy['alpha2'].setValue('alpha')

That's really not what I expected to happen... To me the logic seems like the bottem left quadrant should be r2,g2,b2,a2 right? Apparently not so lets expose all the knobs on this node and see what we have to work with.

for label, knob in sorted(nuke.selectedNode().knobs().iteritems()):
print label, knob.value()

Thats going to return me a nice list like this:

alpha alpha2

autolabel

black red2

blue blue2

bookmark False

cached False

disable False

dope_sheet False

gl_color 0

green green2

green2 green

help

hide_input False

icon

in rgba

in2 rgba

indicators 0.0

knobChanged

label

name test

note_font Verdana

note_font_color 0

note_font_size 11.0

onCreate

onDestroy

out rgba

out2 newLayer

panel None

postage_stamp False

postage_stamp_frame 1.0

red red2

red2 red

selected True

tile_color 0

updateUI

white green2

xpos 41.0

ypos -150.0

 

I started switching some of the values in the shuffleCopy and re-ran the list until I found out what was happening. It turns out that the boxes in the shuffleCopy go down like red, green, blue, alpha, black, white, red2, green2. While it wasn't apparent without exposing the knobs/values, it should be a bit clearer now.

 

Now lets go back to python and try again.

 

shuffle_copy['black'].setValue('red2')

shuffle_copy['white'].setValue('green2')

shuffle_copy['red2'].setValue('blue2')

shuffle_copy['green2'].setValue('alpha2')

 

 

That is the result that I wanted. Here is a chart showing the knob/value combination for each box.

 

 

 

Comments   

 
+3 # Rich Bobo 2014-10-28 20:08
Thanks, Justin!
I also noticed the wacky naming of knobs, but had not taken the time to investigate it, as you have.
Rich
 
 
+3 # Jose Enriquez 2014-11-24 20:20
Hi guys, I just uploaded an script to speed up the merge of different read nodes into channels for rendering a multichannel open exr file in nuke instead of mergeing one by one with a shuffle node You can check it here if you find it useful:
http://www.nukepedia.com/python/render/exr-merge-ztools
 
 
+1 # Ali Jafargholi 2014-12-12 19:13
Nice work Justin, thanks
 
 
+1 # Justin Kirk 2015-01-21 15:44
Most of the research comes from Ali! I just put all his work together.
 
 
+1 # Romain HUBERT 2018-10-23 19:22
I notified issues with :

# If the new channel doesnt exist, create it
nuke.Layer( 'newLayer', ['red', 'green', 'blue','alpha'] )

and this line seems to fix it :
nuke.Layer( 'newLayer', ['newLayer.red' , 'newLayer.green ', 'newLayer.blue' ,'newLayer.alph a'] )
 
 
0 # Lars Erik Eriksen 2019-03-05 20:15
Any Idea of how to edit the layer channels on a layer that has already been created?
 

You have no rights to post comments

We have 3583 guests and 80 members online