List All The Layers In A Render

As far as I could tell you can easily get a list of all the channels in an image with: print nuke.selectedNode().channels() but you couldn’t easily just get a list of the layers, without the individual .red/.green/.blue etc.

This little snippet removes channel name after the layer name (eg. .red) and then groups together all of the remaining names, thus removing all the duplicate layer names to return just a list of layers.

I got this from the Foundry documentation.

# this code takes all the channesl available in the selected node and
# then returns layer names rather than individual channels

node = nuke.selectedNode()
channels = node.channels()
layers = list(set([c.split ('.')[0] for c in channels]))
print layers