Setting default value of a drop down menu in nuke with python
Try the following one. Use this code for nodes with specific names:
def removeOverride():
nuke.toNode("Remove1")['operation'].setValue('keep')
nuke.toNode("Remove1")['channels'].setValue('rgb')
nuke.addOnUserCreate(removeOverride(), nodeClass='Remove')
# use UpperCamelCasing for any class name ('Blur','Read','Remove')
Also for any subsequent nodes created, use this code:
def removeOverride():
for node in nuke.allNodes():
if node.Class() == "Remove":
node["operation"].setValue("keep")
node["channels"].setValue("rgb")
removeOverride()
# OR
nuke.addOnUserCreate(removeOverride(), nodeClass='Remove')
And the last configuration using nuke.selectedNodes()
and nuke.thisNode()
methods is suitable for selected nodes in the DAG:
def removeOverride():
thisNode = nuke.thisNode()
rootDAG = nuke.root()
with rootDAG:
allNodesSelected = nuke.selectedNodes()
try:
allNodesSelected.remove(thisNode)
except:
pass
for node in allNodesSelected:
node["operation"].setValue("keep")
node["channels"].setValue("rgb")
return allNodesSelected
nuke.addOnUserCreate(removeOverride(), nodeClass='Remove')