Python Snippets

Reload read nodes


  1. # Reload all Read nodes
  2. def reloadRead():
  3.     if nuke.selectedNodes('Read'):
  4.         for i in nuke.selectedNodes('Read'):
  5.             i['reload'].execute()
  6.     else:
  7.         for i in nuke.allNodes('Read'):
  8.             i['reload'].execute()
  9. nuke.menu('Nuke').addCommand('Sanjeev/Reload all', 'reloadRead()', 'ctrl+r')




Set label to nodes


  1. def setLabel():   
  2.         # Panel Creation
  3.         panel = nuke.Panel("Set Label      ...by Sanjeev", 150)

  4.         # Knobs Creation
  5.         panel.addSingleLineInput('New Label', '')

  6.         # Buttons
  7.         panel.addButton('Cancel')
  8.         panel.addButton('Ok')
  9.         result = panel.show()
  10.         print result
  11.      
  12.         # Action after getting result
  13.         if result == 1:
  14.             newLabel= panel.value("New Label")
  15.             for i in nuke.selectedNodes():
  16.                 i['label'].setValue(newLabel)

  17. setLabel()


Shuffle between channels


  1. try:
  2.     for i in nuke.selectedNodes():
  3.         bol= next((True for k in i.allKnobs() if k.name()=='channels'), False)
  4.         if bol:
  5.             ### Channel change happen here###
  6.             if i.knob('channels').value() == 'alpha':
  7.                 i.knob('channels').setValue('rgba')
  8.             elif i.knob('channels').value() == 'rgba':
  9.                 i.knob('channels').setValue('all')
  10.             else:
  11.                 i.knob('channels').setValue('alpha')
  12.              
  13.         if not bol:
  14.             raise error
  15. except:
  16.     nuke.message( "Some of the node doesn't have Channels!")

No comments:

Post a Comment