ivanbusquets

Nuke - getKnobType()

Mar 31st, 2013
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. def getKnobType(knob):
  2.     ''' Return a string that identifies the type of knob.
  3.        Useful to distinguish between different types
  4.        of Array and Enumeration knobs that are
  5.        serialized with a different knob ID in tcl.
  6.    '''  
  7.     import re
  8.  
  9.     # Use knob.Class() and return early if Class() is not Array_Knob or Enumeration_Knob
  10.     if knob.Class() not in ['Array_Knob', 'Enumeration_Knob']:
  11.         return knob.Class()
  12.  
  13.     knobName = knob.fullyQualifiedName()
  14.     knobID = nuke.knob(knobName, type = True)
  15.  
  16.     # Get dict of knobtypes
  17.     knobIDs = dict([(v,k) for (k,v) in nuke.KnobType.__dict__.items()])  
  18.  
  19.     # Also use knob.Class() if ID is not found in KnobTypes
  20.     if not (knobID in knobIDs):
  21.         return knob.Class()
  22.  
  23.     #return type as defined in KnobTypes, with some reformatting
  24.     return re.sub( '(?<!^)(?=[A-Z])', '_',  knobIDs[knobID].lstrip('e'))
Advertisement
Add Comment
Please, Sign In to add comment