Skip to content

Instantly share code, notes, and snippets.

@dbr
Created January 18, 2010 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbr/279677 to your computer and use it in GitHub Desktop.
Save dbr/279677 to your computer and use it in GitHub Desktop.
Nuke show-node-with-postage-stamps nonsense
"""Nuke/Python script that displays the selected node in the DAG
using a lot of node postage-stamps.. Not *exactly* useful..
http://img46.imageshack.us/img46/923/nukenodalimgviewer.png
"""
import nuke
def getRGB(node, x, y):
return [node.sample(chan, x, y) for chan in ['red', 'green', 'blue']]
def getColourBlocks(sourcenode, xnumblocks, ynumblocks):
w = sourcenode.width()
h = sourcenode.height()
perWidthStep = w / xnumblocks
perHeightStep = h / ynumblocks
lines = {}
for x in range(xnumblocks):
for y in range(ynumblocks):
curx, cury = perWidthStep * x, perHeightStep * y
cury = h - cury
lines[(x, y)] = getRGB(sourcenode, curx, cury)
return lines
def genNode(x, y):
nn = nuke.nodes.Constant()
nn['label'].setValue("%dx%d" % (x, y))
nn.setXYpos(x, y)
return nn
def genGrid(numx, numy, spacex, spacey):
lines = {}
for x in range(numx):
for y in range(numy):
curx, cury = x * spacex, y * spacey
n = genNode(curx, cury)
lines[(x, y)] = n
return lines
def paintGrid(sourceimg, lines):
for k, v in sourceimg.items():
x, y = k
lines[(x, y)]['color'].setValue(v + [1])
def removeAllConstants():
for x in nuke.allNodes():
if x.Class() == "Constant":
nuke.delete(x)
def selectedToPostagestamps():
# removeAllConstants()
sourceimg = nuke.selectedNode()
sourceimg.setXYpos(-200, -200)
colours = getColourBlocks(sourceimg, 50, 25)
grid = genGrid(50, 25, 100, 100)
paintGrid(colours, grid)
nuke.menu("Nodes").addCommand("Other/Selected to Postage-stamp-viewer", "selectedToPostagestamps()")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment