Skip to content

Instantly share code, notes, and snippets.

@mileslauridsen
Forked from BenMcEwan/defaultBackdrop.py
Created November 7, 2018 05:23
Show Gist options
  • Save mileslauridsen/c7352365aaae65bf576a02b8ba2242b6 to your computer and use it in GitHub Desktop.
Save mileslauridsen/c7352365aaae65bf576a02b8ba2242b6 to your computer and use it in GitHub Desktop.
# --------------------------------------------------------------
# defaultBackdrop.py
# Version: 1.1.0
# Last Updated: January 11th, 2018
# --------------------------------------------------------------
# --------------------------------------------------------------
# USAGE:
#
# Creates a set of default backdrop nodes to help quickly label different sections of a nuke script.
# --------------------------------------------------------------
# --------------------------------------------------------------
# BACKDROP NODE SHORTCUTS :::::::::::::::::::::::::::::::::::::
# --------------------------------------------------------------
import nuke
def defaultBackdrop(name, bgColR, bgColG, bgColB, tColR, tColG, tColB, zIndex, nodes = None):
# Define Colors. The numbers have to be integers, so there's some math to convert them.
bgColor = int('%02x%02x%02x%02x' % (bgColR*255,bgColG*255,bgColB*255,255),16)
textColor = int('%02x%02x%02x%02x' % (tColR*255,tColG*255,tColB*255,255),16)
if nodes is None:
nodes = nuke.selectedNodes()
if len(nodes) == 0:
n = nuke.createNode("BackdropNode")
return n
# Calculate bounds for the backdrop node.
bdX = min([node.xpos() for node in nodes])
bdY = min([node.ypos() for node in nodes])
bdW = max([node.xpos() + node.screenWidth() for node in nodes]) - bdX
bdH = max([node.ypos() + node.screenHeight() for node in nodes]) - bdY
# Expand the bounds to leave a little border. Elements are offsets for left, top, right and bottom edges respectively
left, top, right, bottom = (-70, -140, 70, 70)
bdX += left
bdY += top
bdW += (right - left)
bdH += (bottom - top)
# Set backdrop parameters
n = nuke.nodes.BackdropNode(xpos = bdX,
bdwidth = bdW,
ypos = bdY,
bdheight = bdH,
z_order = zIndex,
tile_color = bgColor,
note_font_color = textColor,
note_font_size=100,
label=name,
name=' ',
note_font='Arial Black')
# Revert to previous selection
for node in nodes:
node['selected'].setValue(True)
# Ensure backdrop is selected, to make moving easier
n['selected'].setValue(True)
nuke.show(n)
return n
# Add the following to menu.py
import defaultBackdrop
# ----- CREATE MENU --------------------------------------------------
# Create a menu in the nodes panel. Uses the default BackdropNode icon, for some nice consistency!
bmBackdrops = nuke.menu('Nodes').addMenu('bmBackdrops', icon='Backdrop.png')
# Our first Backdrop Node default! Remember the parameters outlines above? That's where these come in.
# "Generic" is the name that appears in the menu, we're then looking for the defaultBackdrop.py file (the code above) that's saved in our .nuke folder, and we're calling the defaultBackdrop() function from there.
# " " is setting our label to be blank. In this instance it doesn't need a name.
# The first set of 3 numbers are the R, G and B values that colour the Backdrop Node (0.267, 0.267, 0.267).
# The second set of 3 numbers are the R, G and B values that colour the Text in the Backdrop Node (0.498, 0.498, 0.498).
# Our last parameter, "-5", is our zIndex. It's set to -5, as we want it to be behind every other Backdrop Node in our node graph.
# Lastly, "alt+b" is setting the keyboard shortcut, and "icon=Backdrop.png" is telling Nuke to use the default Backdrop Node icon as the icon for this menu item.
bmBackdrops.addCommand('Generic', 'defaultBackdrop.defaultBackdrop(" ", 0.267, 0.267, 0.267, 0.498, 0.498, 0.498, -5)', 'alt+b', icon="Backdrop.png")
# Following the same explanation from our Generic backdrop node, let's populate our menu with a few more. Notice the icon name is different? I've custom-created icons to match the colour of each backdrop node.
bmBackdrops.addCommand('Plate', 'defaultBackdrop.defaultBackdrop(" PLATE", 0.267, 0.267, 0.267, 0.498, 0.498, 0.498, -1)', icon="/icons/bmBackdrops/BackdropDarkGrey.png")
bmBackdrops.addCommand('Denoise', 'defaultBackdrop.defaultBackdrop(" DENOISE", 0.267, 0.267, 0.267, 0.498, 0.498, 0.498, -1)', icon="/icons/bmBackdrops/BackdropDarkGrey.png")
bmBackdrops.addCommand('Reference', 'defaultBackdrop.defaultBackdrop(" REF", 0.267, 0.267, 0.267, 0.498, 0.498, 0.498, -1)', icon="/icons/bmBackdrops/BackdropDarkGrey.png")
bmBackdrops.addCommand('-', "", "") ### Add separator ###
bmBackdrops.addCommand('Foreground', 'defaultBackdrop.defaultBackdrop(" FG", 0.4, 0.4, 0.4, 0.647, 0.647, 0.647, -2)', icon="/icons/bmBackdrops/BackdropLightGrey.png")
bmBackdrops.addCommand('Background', 'defaultBackdrop.defaultBackdrop(" BG", 0.4, 0.4, 0.4, 0.647, 0.647, 0.647, -2)', icon="/icons/bmBackdrops/BackdropLightGrey.png")
bmBackdrops.addCommand('-', "", "") ### Add separator ###
bmBackdrops.addCommand('3D', 'defaultBackdrop.defaultBackdrop(" 3D", 0.376, 0.286, 0.275, 0.714, 0.427, 0.388, 0)', icon="/icons/bmBackdrops/Backdrop3D.png")
bmBackdrops.addCommand('Camera', 'defaultBackdrop.defaultBackdrop(" CAM", 0.425, 0.14, 0.078, 1, 0.475, 0.424, 0)', icon="/icons/bmBackdrops/BackdropCamera.png")
bmBackdrops.addCommand('Track', 'defaultBackdrop.defaultBackdrop(" TRACK", 0.541, 0.541, 0.541, 0.859, 0.859, 0.859, 0)', icon="/icons/bmBackdrops/BackdropLightGrey.png")
bmBackdrops.addCommand('Matte', 'defaultBackdrop.defaultBackdrop(" MATTE", 0.267, 0.145, 0.145, 0.549, 0.329, 0.329, -1)', icon="/icons/bmBackdrops/BackdropMatte.png")
bmBackdrops.addCommand('Colour Correct', 'defaultBackdrop.defaultBackdrop(" CC", 0.055, 0.282, 0.459, 0.333, 0.745, 1, 0)', icon="/icons/bmBackdrops/BackdropCC.png")
bmBackdrops.addCommand('Lens Effects', 'defaultBackdrop.defaultBackdrop(" LENS FX", 0.443, 0.302, 0.02, 0.718, 0.482, 0.031, 0)', icon="/icons/bmBackdrops/BackdropLensFX.png")
bmBackdrops.addCommand('Grain', 'defaultBackdrop.defaultBackdrop(" GRAIN", 0.541, 0.541, 0.541, 0.337, 0.337, 0.337, 0)', icon="/icons/bmBackdrops/BackdropLightGrey.png")
bmBackdrops.addCommand('-', "", "") ### Add separator ###
bmBackdrops.addCommand('Key', 'defaultBackdrop.defaultBackdrop(" KEY", 0.208, 0.384, 0.173, 0.435, 0.62, 0.357, -1)', icon="/icons/bmBackdrops/BackdropKey.png")
bmBackdrops.addCommand('Despill', 'defaultBackdrop.defaultBackdrop(" DESPILL", 0.278, 0.31, 0.243, 0.467, 0.522, 0.412, 0)', icon="/icons/bmBackdrops/BackdropDespill.png")
bmBackdrops.addCommand('Edges', 'defaultBackdrop.defaultBackdrop(" EDGES", 0.067, 0.09, 0.043, 0.255, 0.337, 0.173, 0)', icon="/icons/bmBackdrops/BackdropEdges.png")
bmBackdrops.addCommand('Paint', 'defaultBackdrop.defaultBackdrop(" PAINT", 0.098, 0.157, 0.063, 0.435, 0.533, 0.337, 0)', icon="/icons/bmBackdrops/BackdropPaint.png")
bmBackdrops.addCommand('Roto', 'defaultBackdrop.defaultBackdrop(" ROTO", 0.173, 0.243, 0.122, 0.369, 0.518, 0.357, 0)', icon="/icons/bmBackdrops/BackdropRoto.png")
bmBackdrops.addCommand('-', "", "") ### Add separator ###
bmBackdrops.addCommand('CG', 'defaultBackdrop.defaultBackdrop(" CG", 0.149, 0.251, 0.286, 0.31, 0.514, 0.584, -1)', icon="/icons/bmBackdrops/BackdropCG.png")
bmBackdrops.addCommand('FX', 'defaultBackdrop.defaultBackdrop(" FX", 0.122, 0.161, 0.188, 0.357, 0.494, 0.541, -1)', icon="/icons/bmBackdrops/BackdropFX.png")
bmBackdrops.addCommand('DMP', 'defaultBackdrop.defaultBackdrop(" DMP", 0.173, 0.129, 0.212, 0.435, 0.341, 0.537, -1)', icon="/icons/bmBackdrops/BackdropDMP.png")
bmBackdrops.addCommand('-', "", "") ### Add separator ###
bmBackdrops.addCommand('Repo', 'defaultBackdrop.defaultBackdrop(" REPO", 0.376, 0.259, 0.435, 0.69, 0.459, 0.733, 0)', icon="/icons/bmBackdrops/BackdropRepo.png")
bmBackdrops.addCommand('Retime', 'defaultBackdrop.defaultBackdrop(" RETIME", 0.475, 0.467, 0.204, 0.714, 0.698, 0.227, 0)', icon="/icons/bmBackdrops/BackdropRetime.png")
bmBackdrops.addCommand('-', "", "") ### Add separator ###
bmBackdrops.addCommand('Out', 'defaultBackdrop.defaultBackdrop(" OUT", 0.22, 0.212, 0.11, 0.541, 0.533, 0.345, 0)', icon="/icons/bmBackdrops/BackdropOut.png")
@jeremy-cox
Copy link

Lines 24 & 25 break in Nuke 13. Here is a fix. Probably a cleaner way to do it, but at least it works.

bgColor = int('%02x%02x%02x%02x' % (int(bgColR*255),int(bgColG*255),int(bgColB*255),255),16)
textColor = int('%02x%02x%02x%02x' % (int(tColR*255),int(tColG*255),int(tColB*255),255),16)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment