Controlling the ShuffleCopy through Python
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
I also noticed the wacky naming of knobs, but had not taken the time to investigate it, as you have.
Rich
http://www.nukepedia.com/python/render/exr-merge-ztools
# 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'] )
RSS feed for comments to this post