Advertisement
Guest User

Untitled

a guest
Mar 15th, 2014
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. def setTileColour(node, red, green, blue):
  2.     '''convert normalised rgb values to a hex value and use the result to cange node's tile_color'''
  3.  
  4.     hexColour = int('%02x%02x%02x%02x' % (red*255,green*255,blue*255,1),16)
  5.     node["tile_color"].setValue(hexColour)
  6.  
  7. def tileColourCB():
  8.     '''callback script that parses a user knob's va;ue wen it's changed and calls setTileColour based on the new knob value'''
  9.  
  10.     node = nuke.thisNode()
  11.     knob = nuke.thisKnob()
  12.     if not knob.name() == 'myColourKnob':
  13.         # if any knob other than the custom knob is changed, don't do anything
  14.         return
  15.     # store colour values for each label used in the custom knob
  16.     colourDict = {'red':(1,0,0), 'green':(0,1,0), 'blue':(0,0,1)}
  17.     # since the custom knob is a cascading pulldown choice knob, split the label and only take the last item as the requested colour label
  18.     colourString = knob.value().split('/')[-1]
  19.     # use the colour label to look up the colour values from the dictionary
  20.     colourValues = colourDict[colourString]
  21.     # assign the colour to the node
  22.     setTileColour(node, *colourValues)
  23.  
  24. nuke.addKnobChanged(tileColourCB, nodeClass='NoOp')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement