Thanks Ben
A useful insight!
Howard
From: Ben Dickson ben.dick...@rsp.com.au
To: Nuke user discussion nuke-users@support.thefoundry.co.uk
Sent: Tuesday, 18 October 2011, 2:59
Subject: Re: [Nuke-users] Diogo's splitLayers.py script
For function runs on selected nodes type utils, I've tried to follow
the the idiom of:
def make_blurs(nodes = None):
if nodes is None:
nodes = nuke.selectedNodes()
created_nodes = []
for n in nodes:
new = nuke.nodes.Blur(inputs = [n]) # or something more useful
# ...
created_nodes.append(n)
return created_nodes
That allows functions to be chained together nicely, since you can do
something like:
starting = nuke.selectedNodes()
blurs = make_blurs(starting)
grades = make_grades(blurs)
The reason to do nodes=None is because..
def func(nodes = nuke.selectedNodes()):
pass
..won't do what you expect - the selectedNodes function gets called a
function-definition time (so probably when Nuke starts up), it's the
same as doing:
default_value = nuke.selectedNodes()
def func(nodes = default_value):
pass
There's a similar, but subtler issue with having mutable objects (like a
list or dict) as default argument:
http://stackoverflow.com/questions/1132941/least-astonishment-in-python-the-mutable-default-argument
Basically having anything other than simple numbers, or True/False as a
default argument value is usually.. suspicious
On 18/10/11 05:44, Diogo Girondi wrote:
Ooops! Howard is right!
You need to feed nuke.selectedNode() or a node object to it. I did that
to allow people to use that function from elsewhere while passing node
objects from loops and whatnots and not just based on the node selection.
Sorry.
Cheers,
Diogo
On 17/10/2011, at 14:21, Howard Jones mrhowardjo...@yahoo.com
mailto:mrhowardjo...@yahoo.com wrote:
Hi
Yes works well - I modified it so it had nuke.selectedNode() fed into
it it.
See below though no doubt the formatting may have screwed.
Howard
### Splits each and every layer on their own pipes using
### shuffle nodes.
### --
### splitLayers.py
### v1.0 - Last modified: 07/08/2009
### Written by Diogo Girondi
### diogogiro...@gmail.com mailto:diogogiro...@gmail.com
import nuke
def splitLayers( node=nuke.selectedNode() ):
'''
Splits each and every layer from the selected node into their own
pipes
'''
ch = node.channels()
layers = []
valid_channels = ['red', 'green', 'blue', 'alpha', 'black', 'white']
for each in ch:
layer_name = each.split( '.' )[0]
tmp = []
for channel in ch:
if channel.startswith( layer_name ) == True:
tmp.append( channel )
if len( tmp ) 4:
for i in range( 4 - len( tmp ) ):
tmp.append( layer_name + .white )
if tmp not in layers:
layers.append( tmp )
for each in layers:
layer = each[0].split( '.' )[0]
ch1 = each[0].split( '.' )[1]
ch2 = each[1].split( '.' )[1]
ch3 = each[2].split( '.' )[1]
ch4 = each[3].split( '.' )[1]
if ch1 not in valid_channels:
ch1 = red red
else:
ch1 = '%s %s' % ( ch1, ch1 )
if ch2 not in valid_channels:
ch2 = green green
else:
ch2 = '%s %s' % ( ch2, ch2 )
if ch3 not in valid_channels:
ch3 = blue blue
else:
ch3 = '%s %s' % ( ch3, ch3 )
if ch4 not in valid_channels:
ch4 = alpha alpha
else:
ch4 = '%s %s' % ( ch4, ch4 )
prefs = in %s %s %s %s %s % (layer, ch1, ch2, ch3, ch4)
shuffle = nuke.createNode( 'Shuffle', prefs, inpanel=False )
shuffle.knob( 'label' ).setValue( layer )
shuffle.setInput( 0, node )
*From:* JKehler jdkeh...@atmosphere-vfx.com
mailto:jdkeh...@atmosphere-vfx.com
*To:* Nuke user discussion nuke-users@support.thefoundry.co.uk
mailto:nuke-users@support.thefoundry.co.uk
*Sent:* Monday, 17 October 2011, 17:26
*Subject:* [Nuke-users] Diogo's splitLayers.py script
Hey.
Just wondering if anyone has had any luck using the splitLayers.py
script.?(Diogo maybe)
I tried running it on an .exr file but nothing happened.
Thanks for the feedback.
JK
___
Nuke-users mailing list
Nuke-users@support.thefoundry.co.uk
mailto:Nuke-users@support.thefoundry.co.uk,
http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users