To Merge here: App Nuke

Technique Section

  • nuke environment setting
  • nuke will auto run all the in the path directories before launch
    import sys
    if nuke.NUKE_VERSION_STRING.startswith('9'):
        nuke.pluginAddPath('./9.0') # relative path
        sys.path.append('D:/myOtherPythonModulePath') # abs path
  • launch nuke with custom python initial script
    Nuke.exe other_args
  • menu creation with one-line and auto creation if not exist
    # it automatically create xTool menu in menubar, 
    # and create "CompHelper" menu item that call function string, with shortcut and icon 
    import sys,os;myPath=r'D:\Dev\CompHelper'
    myPath in sys.path or sys.path.append(myPath);import CompHelper;
    cmd ='Nuke').addCommand("xTool/CompHelper", 'CompHelper.main()',icon=os.path.join(myPath,'icons','CompHelper.png'))
  • save script
    nuke.scriptSave( outScript )
    curScript = nuke.toNode("root").name()

Node attribute knob Operation

  • set knob to readonly/locked
    # lock with a flag
  • root first frame and last frame
    start = int(nuke.Root().knob('first_frame').value())
    end = int(nuke.Root().knob('last_frame').value())
  • get and goto frame
    curFrame = nuke.frame() # get
    nuke.frame(1002) # goto
  • set a nuke node default
    nuke.knobDefault( 'Write.afterRender', 'import myFun;myFun.some_action()')
  • nuke script's root root
    root = nuke.thisNode()
  • read
    my_node = nuke.createNode('Read')
  • get selected nodes with type filtering
    selected = [x for x in nuke.selectedNodes() if x.Class() == 'Read']
  • find all write nodes
    def getNodeByClass(nodeClass, startNode):
        if startNode.Class() == nodeClass:
            yield startNode
        elif isinstance(startNode, nuke.Group):
            for child in startNode.nodes():
                for foundNode in RecursiveFindNodes(nodeClass, child):
                    yield foundNode
    allWriteNodes = [w for w in getNodeByClass('Write', nuke.root())]
  • render write node
    # set after render python script
    cur_node.knob('afterRender').setValue("WriteToMov()") # call a python function after done rendering
    # call render
    nuke.execute( nodeName, firstFrame, lastFrame )

Knob Operation

  • add knob callback

Nuke Tcl Expression


# file attribute expression:
[value rdir]/finals/[value shot]/NK_[value shot].%03d.dpx
# get evaluate result
print (nuke.thisNode()["file"].evaluate())

# mix python in tcl
file "\[value nas_root]/\[value project]/\[value seq]/zup_renders/Comp/\[value RenderType]/\[value shot]_[value FileName]_v[python {str(int(nuke.thisNode()['ver'].value())).zfill(3)} ]/\[value shot]_[value FileName]_v[python {str(int(nuke.thisNode()['ver'].value())).zfill(3)} ].####.\[value file_type]" 

# use cmd
 knobChanged "\ncur=nuke.thisNode()\npathA = \[ cur\[each].value() for each in \['nas_root', 'project', 'seq'] ]\npathB = \['zup_renders/Comp', cur\['RenderType'].value() ]\nsegC = cur\['shot'].value()\nif cur\['FileName'].value() !='':\n    segC+='_'+cur\['FileName'].value()\nsegC+='_v'+ str(int(cur\['ver'].value())).zfill(3)\npathD = \[ segC+'.####.'+cur\['file_type'].value() ]\ncur\['file'].setValue( '/'.join( pathA + pathB + \[segC] + pathD ) )\n"

Nuke API

  • nuke used library: nuke help/Documentation/html/content/comp_environment/third_party_software/third_party_libraries.html