some python snippets for nuke

1. To change selected nodes Values.

for i in nuke.selectedNodes() :
    i['size'].setValue(20)

[what is happening when i run this code in script editor inside nuke?

Most compositors and learners (scripting) question is above one. Here is the answer. When you run this into your nuke script editor it will doing some repeated work. Example if you selecting 10 Blur nodes and run this it will assign the name of i to the 10 Blur nodes and it will start to change the 'size' as 0 - 20 one by one.]


2. Hide all nodes input.

for i in nuke.allNodes() :
    i['hide_input'].setValue(1)

(for active back use 0 on setValue)

3. Hide selected nodes input.

for i in nuke.selectedNodes() :
    i['hide_input'].setValue(1)

4. For lock all connections.

nuke.Root().knob('lock_connections').setValue(1)





5. To set all read node start to custom frame.

for a in nuke.allNodes():
    if a.Class() == 'Read':
        a['frame_mode'].setValue('1')
        a['frame'].setValue('1')

(here i use 1 frame as start frame. If you want to start your read from '1001' use "a['frame'].setValue('1001'))

6. All read nodes missing frames to 'checkerboard'.

for s in nuke.allNodes('Read'):
    s['on_error'].setValue('checkerboard')
7. set all roto nodes output as only alpha.

for s in nuke.allNodes('Roto'):
    s['output'].setValue('alpha')

if you want to output as 'rgba' try

for s in nuke.allNodes('Roto'):
    s['output'].setValue('rgba')

8. For roto nodes default output alpha only.

nuke.knobDefault('Roto.output', 'alpha')
( add this line into your menu.py )
9. For temporarily disable heavy nodes like - Defocus, VectorBlur, Convolve, oflow, TVIscale.

for s in nuke.allNodes():
    classTypes = ['Defocus' , 'VectorBlur', 'Convolve', 'oflow', 'TVIscale', ]
    for n in classTypes:
        if n in s.Class():
            s['disable'].setValue(1)

( While working with bigger shot with lot off layers. Compositing tree became very bigger and heavy. In those kind of situvation we need to disable some heavy processing nodes for quicker preview. Use this script for nuke automatically find those nodes and disable those nodes )

10. Expand selected Groups.

for a in nuke.selectedNodes():
    a.expand()

For expand all group nodes in node graph.

for s in nuke.allNodes('Group'):
    s.expand()

11.For getting sys current Date.  Like ( 30-04-2012 )

[clock format [clock seconds] -format {%d-%m-%Y}]

12. For blur one channel in Nuke.

b = nuke.createNode('Blur')
b['channels'].setValue("green")
b['size'].setValue(100)

blur a layer:

b = nuke.createNode('Blur')
b['channels'].setValue("depth")

13.To set 'Merge' nodes bounding box from union to 'B'.

To selected nodes only:
for s in nuke.selectedNodes("Merge2"):
    s['bbox'].setValue(3)

To all 'Merge' nodes:
for s in nuke.allNodes("Merge2"):
    s['bbox'].setValue(3)

14. To disable extra channels output from 'ScanlineRender'.

By default nukes 'ScanlineRender' nodes render some extra channels rather then 'rgba'. If you have many 'ScanlineRender' node in your script with the default setting, nuke will slow down. To get rid of that extra channel use following simple python script.

Example images:






for s in nuke.selectedNodes("ScanlineRender"):
    s['output_motion_vectors_type'].setValue(0)
    s['MB_channel'].setValue('none')

15. Print all read nodes file path with node name.

for s in nuke.allNodes('Read'):
    print s['name'].value() + ' - ' + s['file'].value()


16. Set transform node's pivot point to center automatically:

for a in nuke.selectedNodes():
a['center'].setExpression('[value name].bbox.r+([value name].bbox.x-[value name].bbox.r)/2', 0)
a['center'].setExpression('[value name].bbox.y+([value name].bbox.t-[value name].bbox.y)/2', 1)
a['center'].clearAnimated()




17. Auto crop based on input bbox.

s = nuke.selectedNode()
s['box'].setExpression('[value name].bbox.x', 0)
s['box'].setExpression('[value name].bbox.y', 1)
s['box'].setExpression('[value name].bbox.r', 2)
s['box'].setExpression('[value name].bbox.t', 3)
s['box'].clearAnimated()


18. Automatically place the cornerPin nodes pin's.
 
selNode = nuke.selectedNode()
selNode['from1'].setExpression('[value name].bbox.x', 0)
selNode['from1'].setExpression('[value name].bbox.y', 1)
selNode['from1'].clearAnimated()
selNode['from2'].setExpression('[value name].bbox.r', 0)
selNode['from2'].setExpression('[value name].bbox.y', 1)
selNode['from2'].clearAnimated()
selNode['from3'].setExpression('[value name].bbox.r', 0)
selNode['from3'].setExpression('[value name].bbox.t', 1)
selNode['from3'].clearAnimated()
selNode['from4'].setExpression('[value name].bbox.x', 0)
selNode['from4'].setExpression('[value name].bbox.t', 1)
selNode['from4'].clearAnimated()
## copying value's from
selNode['to1'].setExpression('[value name].bbox.x', 0)
selNode['to1'].setExpression('[value name].bbox.y', 1)
selNode['to1'].clearAnimated()
selNode['to2'].setExpression('[value name].bbox.r', 0)
selNode['to2'].setExpression('[value name].bbox.y', 1)
selNode['to2'].clearAnimated()
selNode['to3'].setExpression('[value name].bbox.r', 0)
selNode['to3'].setExpression('[value name].bbox.t', 1)
selNode['to3'].clearAnimated()
selNode['to4'].setExpression('[value name].bbox.x', 0)
selNode['to4'].setExpression('[value name].bbox.t', 1)
selNode['to4'].clearAnimated()
19. To change the channel to alpha only to all the blur node which is  connected with roto nodes.

for sel in nuke.allNodes('Roto'):
    for each in sel.dependent():
        if each.Class()=="Blur":
            each['channels'].setValue("alpha")

Comments

Post a Comment

Popular posts from this blog

Export Nuke's retime information

Lock and unLock node settings in nuke

Working with UV pass inside NUKE