Python

Convert rgb to hex for setting the tile color

hexColour = int('%02x%02x%02x%02x' % (r*255,g*255,b*255,1),16)

Add user knobs from python

c = nuke.toNode("YourNode")

text = nuke.Text_Knob(name,label,"text")

c.addKnob(knob)

RENDER EVERY Nth Frame

nuke.execute(writeNode.name(), x, x, 5)

Nuke ProgressBar Example:

import time

myTask = nuke.ProgressTask("Progress")

for n in range (1,11):

     time.sleep(0.1)

     myTask.setProgress((n*100)/10)

     print n

del myTask


Gizmo  Tricks:

Put all functions in one place in a gizmo and execute them separately

Thanks Wouter Gilsing

http://community.foundry.com/discuss/topic/127752


Example:

set cut_paste_input [stack 0]

version 9.0 v9

push $cut_paste_input

NoOp {

name NoOp1

selected true

xpos 144

ypos 168

addUserKnob {20 User}

addUserKnob {22 master l "master (hide this knob)" T "node = nuke.thisNode()\n\ndef function1():\n node.knob('label').setValue('Button 1 was clicked')\ndef function2():\n node.knob('label').setValue('Button 2 was clicked')\ndef function3():\n node.knob('label').setValue('Button 3 was clicked')\n\nfunctionPick = node.knob('functionPicker').value()\n\nif functionPick == '1':\n function1()\nelif functionPick == '2':\n function2()\nelse:\n function3()" +STARTLINE}

addUserKnob {4 functionPicker l "hide this pulldown" -STARTLINE M {1 2 3 "" "" ""}}

addUserKnob {26 ""}

addUserKnob {22 button1 T "node = nuke.thisNode()\n\nnode.knob('functionPicker').setValue('1')\nnode.knob('master').execute()" +STARTLINE}

addUserKnob {22 button2 -STARTLINE T "node = nuke.thisNode()\n\nnode.knob('functionPicker').setValue('2')\nnode.knob('master').execute()"}

addUserKnob {22 button3 -STARTLINE T "node = nuke.thisNode()\n\nnode.knob('functionPicker').setValue('3')\nnode.knob('master').execute()"}

}



TIPS

For setting knob default and adding plugin path use init.py

For making UI stuffs like menus and adding hotkeys use menu.py

________________________________________________________________________________________________________________

For activating the all channels in any multi-channel color knob

knob.setSingleValue(False)

For Ex : nuke.toNode("Grade1")["white"].setSingleValue(False)

________________________________________________________________________________________________________________

Setting Expression in multichannel knobs

first we need to switch the display of the knob from single to multichannel knob using

knob.setSingleValue(False)

then

knob.setExpression("expression as string",channel index)

For Ex : g["white"].setExpression("CurveTool2.intensitydata.r/CurveTool2.intensitydata.r(1)",0)

_______________________________________________________________________________________________________________

Setting values in multichannel knobs

This is pretty easy

knob.setSingleValue(False)

knob.setValue([0,0,0,0])

___________________________________________________________________________________

query nuke hotkeys

for n in nuke.hotkeys().split('\n'):

    print n

__________________________________________________________________________________

set current frame on creation of framehold node

add this in init.py

def setCurrent():

    nuke.thisNode()["first_frame"].setValue(nuke.frame())

nuke.addOnUserCreate (setCurrent, nodeClass="FrameHold")

__________________________________________________________________

Learning Materials:

http://www.nukepedia.com/written-tutorials/using-the-nukemath-python-module-to-do-vector-and-matrix-operations

seq Renamer WIP

import os

node = nuke.selectedNode()

dire = os.path.dirname(node["file"].getValue())

rawSource = os.path.basename(node["file"].getValue())

source = rawSource.split(".")[0]

ext = rawSource.split(".")[-1]

startframe = int(node["origfirst"].getValue())

p = nuke.Panel("Sequence Renamer")

p.addSingleLineInput("source",source)

p.addSingleLineInput("newName",source)

p.addSingleLineInput("startframe",startframe)

p.addSingleLineInput("inc",1)

p.show()

oldName = p.value("source")

newName = p.value("newName")

startframe = int(p.value("startframe"))

increment = int(p.value("inc"))

frameNum = startframe

files = os.listdir(dire)

for pic in files:

    source = oldName+"."+str(frameNum)+"."+ext

    print source

    if pic == source:

        old = dire+"/"+source

        new = dire+"/"+newName+"."+str(frameNum)+"."+ext

        print old

        print new

        os.rename(old,new)

        frameNum += 1