A friendlier way to use Nuke's Knob Flags

  Nuke Python


Flags can change a knob’s appearance or behaviour. They are useful for doing things like:

  • Disabling knobs
  • Making them invisible
  • Making them read only
  • Limiting the value to a range, etc.

Only a few knob flags are registered in Nuke’s Python module, which makes them a little difficult to use.

For example, the DISABLE flag exists, so we could disable Grade1's mix knob like this:

1nuke.toNode("Grade1").knob("mix").setFlag(nuke.DISABLE)

For some flags, you need to find the hexadecimal value, which is buried in a Knob.h file in nuke’s install directory: C:\Program Files\Nuke16.0v1\include\DDImage\Knob.h

For example, if I wanted to remove the slider from a mix knob, this wouldn’t work:

1nuke.toNode("Grade1").knob("mix").clearFlag(nuke.SLIDER)

We have to use the hex value, which is: 0x0000000000000002.

1nuke.toNode("Grade1").knob("mix").clearFlag(0x0000000000000002)

That’s tough to remember, so I created a simple python script that allows you to just use the name. You can get that from GitHub. This is also a great place to reference all the knob flags that are available.

After placing that file in your ~/.nuke directory, you can use it like this:

1from nuke_flags_lookup import get_nuke_flag_from_name as flag
2
3nuke.toNode("Grade1").knob("mix").setFlag(flag("SLIDER"))