Advertisement
Guest User

knobChanged nuke node color change example

a guest
Mar 15th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. # Run with a node like this selected:
  2. '''
  3. NoOp {
  4. name NodeColor
  5. addUserKnob {20 NodeColor}
  6. addUserKnob {4 node_color t "Set Node Color" M {red green blue yellow}}
  7. }
  8. '''
  9.  
  10. n = nuke.selectedNode()
  11. n['knobChanged'].setValue('''
  12. # nuke.thisNode()  returns the node that this code is running in
  13. n = nuke.thisNode()
  14. # nuke.thisKnob() returns the value of the current knob being changed when run as a callback
  15. k = nuke.thisKnob()
  16. # Only trigger the callback if the changed knob name is 'node_color'
  17. if k.name() == 'node_color':
  18.    # Figure out which color the menu was set to
  19.    menu_val = k.value()
  20.    if menu_val == 'red':
  21.        color = (1,0,0)
  22.    elif menu_val == 'green':
  23.        color = (0,1,0)
  24.    elif menu_val == 'blue':
  25.        color = (0,0,1)
  26.    elif menu_val == 'yellow':
  27.        color = (0.5,0.5,0)
  28.    # Format the color into the proper hex code that the tile_color knob accepts.
  29.    hex_color = int('%02x%02x%02x%02x' % (color[0]*255, color[1]*255, color[2]*255, 1), 16)
  30.    n['tile_color'].setValue(hex_color)''')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement