Previously, in Nuke Comping Strategies: Label Things, we examined Nuke’s built-in tools for taking notes and finding them again. Here are two ways to make our labeling easier and deeper.
Introspective Labels
Labeling nodes manually gets a bit dicey when we’re labeling with data that’s easily changeable. The Blur node above is labeled with the size of the blur it’s making. That’s super-handy when we’re reading the node graph because we don’t have to open the Blur’s control panel to see how much blur it’s giving us. But if we’re doing this manually, we have to remember to update the label every time we change the blur size. Ick. Nobody’s ever going to remember to update those labels.
That’s where introspective labeling comes in. Nuke comes with the scripting language TCL built in, and we can use that to make labels that update themselves when we twiddle knobs. For example, put this in the Label knob of a Blur node: [value size]
. The square brackets tell Nuke to evaluate the text inside them as a TCL expression, getting the value of the node’s size knob, and then put the result into the label in place of the TCL script. Now the node’s label will update automatically when we change the size knob.
We can apply this idea in lots of places, such as a Transform that tells us its filter mode (filter: [value filter]
), or for making it clear whether a Tracker is stabilizing or matchmoving ([value transform]
).
Each of these introspective labels means we don’t have to open the node’s control panel to see how it’s set up. It’s telling us in the node graph.
One thing to watch out for is that sometimes the knob names as Nuke knows them internally are not the same as the labels they have in the graphical user interface (GUI). If you’re not seeing the result you expect, hover your mouse over the knob and look at the tooltip. In the case below, Grade’s “gain” knob is actually labeled “white” internally. Use the knob name that appears in the tooltip.
We can even use TCL to reach back up the pipe to the top node in a graph and grab its name with [value [topnode].name]
. Note that topnode follows the B pipe.
Topnode and careful node naming can help make the hidden inputs often found in a DasGrain setup more easily understandable. Sure, we could have labeled those dots manually, but this way we can see right away if their inputs ever get accidentally patched to something else. It happens!
One other thing to watch out for if we plan to use this technique a lot is that evaluating expressions relatively lightweight, but can potentially bog Nuke down if we have a lot of them. Switching to lazy expression evaluation will help lighten the load. In Nuke Preferences, go to Performance => Expressions, and set the Expression Re-Evaluation mode to “lazy.”
For more information about how TCL works in Nuke, pull down the Help menu to “Documentation” and follow the “TCL Scripting” link.
editLabel(), a. k. a. Building the Missing Keyboard Shortcut for Labeling
One drawback to the Label knob is that we need to open the node’s properties panel and switch to the Node tab before we can leave ourselves a note. Maybe this is why so many nodes go unlabeled. Why doesn’t Nuke come with a keyboard shortcut for easily editing node labels?!
Don’t fret! We can make our own. Here’s how.
To create this shortcut, we’ll be editing our menu.py
file. Don’t know what that is? Have a look at this explanation from Foundry: What are the init.py and menu.py startup script files? Python scripting in Nuke is a rather deep rabbit hole that we won’t dive down here. If you’re not comfortable making and editing this file or writing Python generally, stop now and read through Nuke’s documentation or find someone to guide you.
Assuming that you’re starting with a brand-new, empty menu.py
file. Add the following editLabel()
function:
# Edit Label
def editLabel():
"""Pop up a dialog allowing the user to edit the contents of the selected node's label."""
# selectedNodes() is much easier to work with than selectedNode()
nodes = nuke.selectedNodes()
if len(nodes) < 1:
return
elif len(nodes) > 1:
nuke.message('Edit Label: Too many nodes selected. One at a time, please.')
return
node = nodes[0]
label = node.knob('label')
contents = label.value()
new_contents = nuke.getInput('Edit label', contents)
if new_contents is None:
return
if contents != new_contents:
label.setValue(new_contents)
As it says in the document string, this function pops up a dialog that you will use to edit the label of the node that you have selected. Now we need to tie this function to a keyboard shortcut (Control+L) so we can trigger it wherever we want. Add a few blank lines after the editLabel()
function, and add this chunk. Feel free to put your name in place of “UserName
”
m = nuke.menu('Nodes')
user = 'UserName'
tm = m.addMenu(user)
tm.addCommand('Edit Label', "editLabel()", shortcut='Ctrl+L')
These lines create a new menu in Nuke’s Nodes panel that has whatever name you put in instead of UserName
. You did replace UserName
, didn’t you? Once menu.py
is complete, restart Nuke so that it picks up the new code. Notice the new menu in the Nodes panel? Now, give editLabel()
a try. Select a node and hit Ctrl+L
. Type something in the text box and hit return. Nifty, right?
Hands-free Labeling
Being able to easily change a node’s label is nifty. But what if we didn’t have to do it at all? What if the label we want could automatically be inserted when we create the node? It’s possible using Nuke’s knobDefault()
function. Add the following to menu.py:
nuke.knobDefault("Blur.label", "[value size]")
Restart Nuke to read in the updated menu.py. Then notice that each Blur node we drop into the node graph displays the blur size right on it.
We can use the same approach to make Trackers that show their transform mode and reference frame values. Notice that we’re telling Nuke to set a knob default for “Tracker4,” even though the node is labeled “Tracker” in the GUI. This is another one of those internal vs. GUI name situations like with the knobs above. Select the node and hit i
to show the info panel and use the name that is listed under “Class.”
nuke.knobDefault("Tracker4.label", "[value transform]\nref: [value reference_frame]")
Or Multipy, Add, and Gamma nodes that show their current value.
nuke.knobDefault("Multiply.label", "[value value]")
nuke.knobDefault("Add.label", "[value value]")
nuke.knobDefault("Gamma.label", "[value value]")
Notice what happens to the label when we split the Value knob and set different values for red, green, blue, and alpha. Neat, huh?
We’re only scratching the surface here. knobDefault()
can be used for lots of other handy things. Have a look at Nuke’s documentation to get going with it.
https://learn.foundry.com/nuke/developers/131/pythondevguide/_autosummary/nuke.knobDefault.html
There we have it — three ways to make labeling easier and even more useful so we can get more done with less effort. Let me know how these work for you!