assigning expression to nodes with python

Hi all.

I’m working on a shot setup/update script that essentially creates a noOp node with some knobs, including a maya render dir path, version, first frame, last frame, frame offset etc.
I got it all pretty much working, but the last thing I need to do is to hook all the selected read nodes to the noOp node via expressions controlling their filename (base path), first frame, last frame and frame offset.

Code:

def setup()
  sn = nuke.selectedNodes()
  rn = nuke.selectedNodes('Read')
  first = 1
  last = XXX
  offset = XXX
  ...
  ...
  ...
  for n in sn:
    n.knob("selected").setValue(False)    #deselect all nodes so the noOp gets created as a standalone node, not connected to anything

  sourceNode = nuke.createNode("NoOp", "name asdf", inpanel = True)
  #and then add knobs and assign values from input
 
#I have all my variables and the noOp node gets created with its knobs and values.
#All I need is to do THIS (badly described with pseudo code:

for n in rn:           
    n.['first].setValue(nuke.expression("sourceNode.first"))     
    n.['last].setValue(nuke.expression("sourceNode.last"))
    n['frame_mode'].setValue(2)  #This sets Read node's frame mode to 'Offset'
    n['frame'].setValue(offset)  #This assigns the value from user input


No Responses to “assigning expression to nodes with python”

Post a Comment