Brendan Abel
Brendan Abel

Reputation: 37559

How to add a Group Knob in nuke using python api

Using tcl script in nuke, adding a group knob to a node looks like this

addUserKnob {20 start_group l "My Group" n 1}
... add other knobs
addUserKnob {20 end_group l endGroup n -1}

It appears that the Group knob uses the same knob type as the Tab knob, except that it uses the n keyword argument. I don't see any information in the python api documentation on how to set the n argument so that nuke creates a Group instead of a Tab.

My python code looks something like this

# Get node
node = nuke.toNode('MyNode')

# Add new tab to node
tab = nuke.Tab_Knob('custom_tab', 'Custom Tab')
node.addKnob(tab)

# Add a group knob
group = nuke.Tab_Knob('group_1', 'Group 1')  # some other argument or flag?
node.addKnob(group)

# Add some other knobs
name = nuke.String_Knob('name', 'Name')
node.addKnob(name)

# Add some type of "end group" knob?
?

I'm assuming I should be using the Tab_Knob in python just like I use the Tab knob type (i.e. 20) in tcl script, and that there is both a start and end knob for the group, but I'm not sure how that should be done in python.

Upvotes: 3

Views: 4843

Answers (1)

Brendan Abel
Brendan Abel

Reputation: 37559

Here is how you add Group knobs using python in nuke.

node = nuke.toNode('MyNode')

# A Group node is created by passing a 3rd argument to the Tab Knob

# This will create a Group knob that is open by default
begin = nuke.Tab_Knob('begin', 'My Group :', 1)

# Alternatively, if you want to create a Group knob that is closed by 
# default, you can pass this constant in as the 3rd argument instead
# of 1
begin = nuke.Tab_Knob('begin', 'My Group :', nuke.TABBEGINCLOSEDGROUP)

# Add Group knob to node
node.addKnob(begin)

# Create and add some other knobs.  They will be inside the group.
button1 = nuke.PyScript_Knob("button1", "Button 1")
button2 = nuke.PyScript_Knob("button2", "Button 2")
button3 = nuke.PyScript_Knob("button3", "Button 3")
node.addKnob(button1)
node.addKnob(button2)
node.addKnob(button3)

# Create and add a Close group knob
begin = nuke.Tab_Knob('begin', 'My Group :', -1)

Upvotes: 2

Related Questions