I have worked at several places with a ctrl + B hotkey to create backdrop and usually use it in my project to keep things nice and readable. I went ahead decided to make one from scratch myself with my preferred color setup for speed. This took me a bit longer than I would have like but, live and learn! Feel free to change the colors around to whatever you would like!
Installation: Just copy the script below into your existing menu.py file in your .nuke folder, save, and run nuke.
import colorsys
def adjust_color(color_hex, desaturate_amount=0.5, darken_amount=0.3):
# Convert hex to RGB
r = ((color_hex >> 24) & 0xFF) / 255.0
g = ((color_hex >> 16) & 0xFF) / 255.0
b = ((color_hex >> 8) & 0xFF) / 255.0
a = (color_hex & 0xFF) / 255.0
# Convert RGB to HSV
h, s, v = colorsys.rgb_to_hsv(r, g, b)
# Reduce saturation
s *= (1 - desaturate_amount)
# Reduce value (darken)
v *= (1 - darken_amount)
# Convert back to RGB
r, g, b = colorsys.hsv_to_rgb(h, s, v)
# Convert back to hex
return int(r * 255) << 24 | int(g * 255) << 16 | int(b * 255) << 8 | int(a * 255)
def create_backdrop():
selected_nodes = nuke.selectedNodes()
if not selected_nodes:
nuke.message("No nodes selected")
return
# Prompt the user for the backdrop name
name_prompt = nuke.getInput("Enter a name for the backdrop:", "Selected Nodes")
if name_prompt is None:
return
# Define the color options with desaturated and darkened values
colors = {
"Red": adjust_color(0xFF0000FF),
"Green": adjust_color(0x00FF00FF),
"Blue": adjust_color(0x0000FFFF),
"Yellow": adjust_color(0xFFFF00FF),
"Cyan": adjust_color(0x00FFFFFF),
"Magenta": adjust_color(0xFF00FFFF)
}
# Prompt the user to select a color
color_names = list(colors.keys())
color_prompt = nuke.Enumeration_Knob('color', 'Select color', color_names)
panel = nuke.Panel("Backdrop Color Selection")
panel.addEnumerationPulldown("Select color", " ".join(color_names))
if not panel.show():
return
selected_color_name = panel.value("Select color")
color_value = colors[selected_color_name]
# Format the label with HTML to make it centered and bold
formatted_label = f'<center><b>{name_prompt}</b></center>'
# Calculate the bounding box of the selected nodes
x_min = min([node.xpos() for node in selected_nodes])
y_min = min([node.ypos() for node in selected_nodes])
x_max = max([node.xpos() + node.screenWidth() for node in selected_nodes])
y_max = max([node.ypos() + node.screenHeight() for node in selected_nodes])
# Create the backdrop node
backdrop = nuke.createNode('BackdropNode')
backdrop['xpos'].setValue(x_min - 10)
backdrop['ypos'].setValue(y_min - 80)
backdrop['bdwidth'].setValue(x_max - x_min + 20)
backdrop['bdheight'].setValue(y_max - y_min + 90)
backdrop['label'].setValue(formatted_label)
backdrop['tile_color'].setValue(color_value)
# Add the create_backdrop function to the Nuke menu and assign the hotkey Ctrl + B
nuke.menu('Nuke').addCommand('Custom/Create Backdrop', 'create_backdrop()', 'Ctrl+B')
Leave a Reply