The difference between .getValue and .toScript for Nuke knobs

Posted 8 January, 2013 Anthony Tan (staring at yet another render. But still loving it for some reason..)

« previous | next »

tags: nuke

Inspired (sorta) by an answer I put up over on stackoverflow thought it might be worth just reposting here, in my own little stash of personal memory.

The basic problem was that user1917081 was trying to write up a script that would take input from two text fields, using one as the name of the knob to set, and the second as the value to set and could be any free text. Here's the original code block:

curSel = nuke.selectedNodes() 
knobToChange = nuke.thisNode()['knobname'].getValue() 
codeIn = nuke.thisNode()['codeinput'].getValue() 

for x in curSel: 

This works fine while you're setting simple strings like "foo" and values like 3.1415, but say you wanted to set the label of 50 Transform nodes to "rotate: [value rotate]", you'd find the label being populated with the literal text nothing is named "rotate". This is a tad confusing, but it's easily solved by changing from .getValue() to .toScript()

Recalling that in Nuke, pretty much any place you can type you can place TCL, if you inspect the knob object, you'll notice that while you add something called a "Text Input Knob", it's actually returning an EvalString_Knob and the getValue call gives you the value of the knob.

Note the keyword here being 'value'.

The value of an EvalString_Knob is not the script itself, it's the result of the script's evaluation, and so will return the TCL error (or TCL result), hence the error message and the string literal being set in the target nodes.

A primitive HFR test, and cubes. Of course.
Transferring information (like colour) between particles
tags: nuke