Difference between revisions of "Nuke Python"
Jump to navigation
Jump to search
(→Export multi files in DXV) |
|||
Line 85: | Line 85: | ||
</pre> | </pre> | ||
− | === Export | + | === Export multiple files in DXV === |
<pre> | <pre> | ||
− | + | //This script comes from the great Benjamin Vedrenne. DXV is the codec made by and for Resolume. | |
− | + | //Select all Read nodes or sources first. | |
− | + | //This script create a write node under each selected read nodes. Easy for fast and massive file conversion TO VIDEO. | |
for oReadNode in nuke.selectedNodes(): | for oReadNode in nuke.selectedNodes(): | ||
Line 113: | Line 113: | ||
Write.knob('settings').setValue('000000000000000000000000000001b67365616e000000010000000100000000000001a276696465000000010000000f00000000000000227370746c0000000100000000000000004458443300000000002000000300000000207470726c000000010000000000000000000000000019000000000000000000246472617400000001000000000000000000000000000000530000010000000100000000156d70736f00000001000000000000000000000000186d66726100000001000000000000000000000000000000187073667200000001000000000000000000000000000000156266726100000001000000000000000000000000166d70657300000001000000000000000000000000002868617264000000010000000000000000000000000000000000000000000000000000000000000016656e647300000001000000000000000000000000001663666c67000000010000000000000000004400000018636d667200000001000000000000000052534c4d00000014636c75740000000100000000000000000000001c6364656300000001000000000000000043736552000000000000001c766572730000000100000000000000000003001c00010000') | Write.knob('settings').setValue('000000000000000000000000000001b67365616e000000010000000100000000000001a276696465000000010000000f00000000000000227370746c0000000100000000000000004458443300000000002000000300000000207470726c000000010000000000000000000000000019000000000000000000246472617400000001000000000000000000000000000000530000010000000100000000156d70736f00000001000000000000000000000000186d66726100000001000000000000000000000000000000187073667200000001000000000000000000000000000000156266726100000001000000000000000000000000166d70657300000001000000000000000000000000002868617264000000010000000000000000000000000000000000000000000000000000000000000016656e647300000001000000000000000000000000001663666c67000000010000000000000000004400000018636d667200000001000000000000000052534c4d00000014636c75740000000100000000000000000000001c6364656300000001000000000000000043736552000000000000001c766572730000000100000000000000000003001c00010000') | ||
− | + | //this is to get advanced codec settings. Copy the long string returned | |
i = nuke.selectedNode() | i = nuke.selectedNode() |
Revision as of 00:13, 8 June 2019
Contents
- 1 Nuke Python Scripts
- 1.1 Create multiple Writes nodes for multiples Reads - With RGBA channels activated
- 1.2 Change specific attribute on all nodes
- 1.3 Set localizationPolicy off on all Read nodes
- 1.4 Set value of BBox parameter in Merge nodes to B
- 1.5 Count selected nodes
- 1.6 Export multiple files in DXV
- 1.7 Maxwell Render - Check .mxi sequence Sampling levels
Nuke Python Scripts
Create multiple Writes nodes for multiples Reads - With RGBA channels activated
//Select Read nodes first root_frame_path = "/YOUR_PATH" nodes = nuke.selectedNodes() for n in nodes: roto_name = n.name() n.setSelected(True) w = nuke.createNode( "Write" ) write_name = roto_name.replace("Roto", "Write_") w.knob("name").setValue(write_name) image_path = "{root_frame_path}/{write_name}.png".format(root_frame_path=root_frame_path, write_name=write_name) w.knob("file").setValue(image_path) for a in nuke.allNodes('Write'): a['channels'].setValue('rgba')
Change specific attribute on all nodes
//Works also with "selectedNodes" //"render_mode" and "textured+wireframe" are examples of attributes to be changed. sn = nuke.allNodes() for n in sn: n.knob('render_mode').setValue("textured+wireframe") //Alternative script for selectedNodes: for a in nuke.selectedNodes('Write'): a['channels'].setValue('rgba') //Alternative script for allNodes: for a in nuke.allNodes('Write'): a['channels'].setValue('rgba')
Set localizationPolicy off on all Read nodes
sn = nuke.allNodes() for n in sn: n.knob('localizationPolicy').setValue("off")
Set value of BBox parameter in Merge nodes to B
for n in nuke.allNodes('Merge2'): n['bbox'].setValue("B")
Count selected nodes
len(nuke.selectedNodes())
Export multiple files in DXV
//This script comes from the great Benjamin Vedrenne. DXV is the codec made by and for Resolume. //Select all Read nodes or sources first. //This script create a write node under each selected read nodes. Easy for fast and massive file conversion TO VIDEO. for oReadNode in nuke.selectedNodes(): oPath = oReadNode['file'].value() first = oReadNode['first'].value() last = oReadNode['last'].value() newPath = oPath.split('/')[-2] newPath = newPath.replace(".%03d.png","") oReadNode['selected'].setValue(True) Write = nuke.createNode ("Write") osdir = 'C:/DXV/tmp' Write.knob('file').setValue(osdir+'/'+newPath+".mov") Write.knob('file_type').setValue('mov') Write.knob('codec').setValue('DXD3') Write.knob('fps').setValue(25) Write.knob('quality').setValue('High') Write.knob('use_limit').setValue(True) Write.knob('first').setValue(first) Write.knob('last').setValue(last) Write.knob('settings').setValue('000000000000000000000000000001b67365616e000000010000000100000000000001a276696465000000010000000f00000000000000227370746c0000000100000000000000004458443300000000002000000300000000207470726c000000010000000000000000000000000019000000000000000000246472617400000001000000000000000000000000000000530000010000000100000000156d70736f00000001000000000000000000000000186d66726100000001000000000000000000000000000000187073667200000001000000000000000000000000000000156266726100000001000000000000000000000000166d70657300000001000000000000000000000000002868617264000000010000000000000000000000000000000000000000000000000000000000000016656e647300000001000000000000000000000000001663666c67000000010000000000000000004400000018636d667200000001000000000000000052534c4d00000014636c75740000000100000000000000000000001c6364656300000001000000000000000043736552000000000000001c766572730000000100000000000000000003001c00010000') //this is to get advanced codec settings. Copy the long string returned i = nuke.selectedNode() print i.knob('settings').value()
Maxwell Render - Check .mxi sequence Sampling levels
//This script comes from the great Marc Dubrois. def checkMXI_SL(): '''takes mxi read node and checks its SLs metadata and outputs frames under certain treshold''' sl_threshold = 18.0 txt = nuke.getInput('Print frames with SL below:', str(sl_threshold)) if txt: sl_threshold = float(txt) output = '' task = nuke.ProgressTask("Checking MXI SLs") task.setMessage("Progress") for node in nuke.selectedNodes(): if node.Class() == 'Read': firstframe = int(node['first'].value()) #lastframe = firstframe + 10 lastframe = int(node['last'].value()) for i in range(firstframe, lastframe): percentage = int(100.0*(i-firstframe)/(lastframe-firstframe)) task.setProgress(percentage) if task.isCancelled(): break; sl = node.metadata('SAMPLING_LEVEL',i) if sl < sl_threshold: task.setMessage('Frame ['+str(i)+'] SL'+"{0:.1f}".format(sl)) logline = 'Frame ' + str(i) + ': ' + "{0:.2f}".format(sl) + '\n' output = output + logline task.setProgress(100) del task p = nuke.Panel('Results') if output == '': output = 'All MXI are above or equal to '+str(sl_threshold) p.addNotepad('Results:',output) ret = p.show() checkMXI_SL()