Reputation: 9
For what I found on the web I am not sure if this is possible but I'll ask anyway.
I would like to be able to retrieve the index of a user_knob I previously add via python within my properties panel.
I have a Nuke node to which I added 2 User Tabs (A and B). In the Tab A, I want to be able to insert and remove user_knob with Python when the user clicks on a button. I understand that in order to do that I have to remove all the user_knob from the point where I want to insert the new user_knob, add the new user_knob then put back all the other user_knob after that.
My issue is that I cannot retrieve the index position of the user_knob I would like to take as a starting point so I know from which index I need to run the removeKnob loop.
I have the list of all user knob types and there respective ID number so I know that #1 is for a string, #4 for a pulldown choice menu, #22 for a PyScript Button, #20 for a Tab, etc...
When I look at the node's plain text in a text editor I can see the logic :
addUserKnob {20 new_custum_tab l Name of New Tab}
I can also access a user knob using its index position within the property panel, so if I want to access the 35th knob (which for instance is a PyScript Button named 'pyscript_button_01') I would go with :
node = nuke.selectedNode()
user_knob_index_position = 35
knob_35th = node.knob(user_knob_index_position)
print knob_35th.name()
>>> Result: pyscript_button_01
But I don't know how to reverse it. I would like to be able to do :
node = nuke.selectedNode()
user_knob_name = "pyscript_button_01"
user_knob = node.knob(user_knob_name)
user_knob_index_position = node.getIndex(user_knob)
print user_knob_index_position
>>> Result: 35
Any idea ? Thanks
Upvotes: 0
Views: 1026
Reputation: 1
node.numKnobs()
returns the amount of knobs stored in a node.
You can the iterate and retrieve the index, thus the name of your knob :
for index in range(node.numKnobs()):
if 'your name' in node.knob(index).name():
print index
using list comprehension:
[index for index in range(node.numKnobs()) if 'your name' in node.knob(index).name()]
Upvotes: 0