Last active
November 29, 2019 07:40
-
-
Save davidlatwe/519528bb01b4ff816389464ec2709e97 to your computer and use it in GitHub Desktop.
[Nuke] Listing all user defined knobs in given node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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