Skip to content

Instantly share code, notes, and snippets.

@davidlatwe
Last active November 29, 2019 07:40
Show Gist options
  • Save davidlatwe/519528bb01b4ff816389464ec2709e97 to your computer and use it in GitHub Desktop.
Save davidlatwe/519528bb01b4ff816389464ec2709e97 to your computer and use it in GitHub Desktop.
[Nuke] Listing all user defined knobs in given node
import nuke
import re
def list_user_knobs(node):
"""Get user defined knobs
Args:
node (nuke.Node): Nuke node object
Returns:
list: A list of nuke.Knob object
"""
user_knobs = list()
pattern = ("(?<=addUserKnob {)"
"([0-9]*) (\\S*)" # Matching knob type and knob name
"(?=[ |}])")
tcl_script = node.writeKnobs(nuke.WRITE_USER_KNOB_DEFS)
result = re.search(pattern, tcl_script)
if result:
first_user_knob = result.group(2)
# Collect user knobs from the end of the knob list
for knob in reversed(node.allKnobs()):
user_knobs.insert(0, knob)
if knob.name() == first_user_knob:
break
return user_knobs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment