No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

autoBackdrop.py 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # autobackdrop.py
  2. # Conversion to Python by michael@yawpitchroll.com
  3. # Derived from a TCL original by frank@beingfrank.info [last modified 10.01.2006]
  4. # Creates a backdrop node that automatically encompasses all selected nodes and has a random color
  5. # Python version last midified 03.04.2008
  6. # 110608 mod by Gabor L. Toth: Backdrop now using not-so-bright-and-saturated-colors. Pastel colors only.
  7. """
  8. AutoBackDrop for Nuke:
  9. Creates a Backdrop node that automatically encompasses all selected nodes
  10. and assigns a random color to the Backdrop.
  11. """
  12. import nuke
  13. import nukescripts
  14. #from random import randint
  15. import random
  16. def AutoBackDrop():
  17. """
  18. Creates a backdrop node with a random color between minCol and maxCol.
  19. Allows some customization to the border around the selected nodes by
  20. modification of some in-file variables. Also allows the user to set
  21. a boolean to decide if they want the Backdrop non-stick (allows backdrop
  22. to be repositioned without moving nodes, will have to click on the DAG
  23. to 'stick' nodes to backdrop) or sticky (backdrop automatically de-
  24. selected, nodes 'stuck' to backdrop (similar to using the Group
  25. command in Shake as an organization Backdrop).
  26. """
  27. # -----> BEGIN USER CUSTOMIZATION <-----
  28. # minCol and maxCol restrict color range
  29. # 1 (full black) to 109951162776 (full white)
  30. minCol = 1
  31. maxCol = 1099511627776
  32. # leftBord, rightBord, topBord, and bottomBord define the border width of the backdrop from
  33. # the left-most, right-most, top-most, and bottom-most nodes (respectively). Positive integers
  34. # will expand the border from default, while negative integers will shrink it.
  35. leftBord = 0
  36. rightBord = 0
  37. topBord = 0
  38. bottomBord = 0
  39. # nonStick defines the "sticky" behavior of the encompassed nodes when
  40. # the backdrop is built. If 'true' the nodes will not be 'sticky' and
  41. # user will have to click on elsewhere on the DAG to 'activate' the backdrop
  42. # (same as normal Backdrop behavior). If 'false' the nodes will 'stick' as
  43. # soon as the AutoBackDrop is created. Default is 'false'
  44. nonStick = False
  45. # -----> END USER CUSTOMIZATION <-----
  46. #Check for selected nodes, create simple backdrop if empty, else create autobackdrop
  47. selection = nuke.selectedNode()
  48. if selection is None:
  49. bd = nuke.createNode("BackdropNode")
  50. #bd.knob("tile_color").setValue(randint(minCol, maxCol))
  51. bd.knob("tile_color").setValue(getRandomPastelColor())
  52. bd.knob("selected").setValue(True)
  53. return
  54. selection = nuke.selectedNodes()
  55. #Find the extreme X and Y positions of the selected nodes
  56. curX = set([i.knob("xpos").value() for i in selection if i.Class()!="BackdropNode"])
  57. curY = set([i.knob("ypos").value() for i in selection if i.Class()!="BackdropNode"])
  58. bdropX = set([i.knob("xpos").value() for i in selection if i.Class()=="BackdropNode"])
  59. bdropY = set([i.knob("ypos").value() for i in selection if i.Class()=="BackdropNode"])
  60. bdropW = set([(i.knob("bdwidth").value() + i.knob("xpos").value()) for i in selection if i.Class()=="BackdropNode"])
  61. bdropT = set([(i.knob("bdheight").value() + i.knob("ypos").value()) for i in selection if i.Class()=="BackdropNode"])
  62. minX = min(curX|bdropX)
  63. minY = min(curY|bdropY)
  64. curX = set([(i+120) for i in curX])
  65. bdropW = set([(i + 40) for i in bdropW])
  66. maxX = max(curX|bdropW)
  67. curY = set([(i+120) for i in curY])
  68. bdropT = set([(i + 56) for i in bdropT])
  69. maxY = max(curY|bdropT)
  70. #Create BackDrop encompassing all selected nodes and assign random color to Backdrop
  71. bd = nuke.createNode("BackdropNode")
  72. bd.knob("xpos").setValue(minX-(20+leftBord))
  73. bd.knob("ypos").setValue(minY-(30+topBord))
  74. bd.knob("bdwidth").setValue((maxX-minX)+(rightBord))
  75. bd.knob("bdheight").setValue((maxY-minY)+(bottomBord))
  76. bd.knob("tile_color").setValue(getRandomPastelColor())
  77. bd.knob("selected").setValue(nonStick)
  78. def getRandomPastelColor():
  79. import random
  80. med = random.random()/4+0.10
  81. #print 'Mean= ' + str(med)
  82. treshold = 0.1
  83. r = abs(random.triangular(med-treshold, med+treshold))
  84. g = abs(random.triangular(med-treshold, med+treshold))
  85. b = abs(random.triangular(med-treshold, med+treshold))
  86. a = 1
  87. print ('r: ' + str(r) + ' g: ' + str(g) + ' b: ' + str(b) )
  88. color = int('%02x%02x%02x%02x' % (r*255,g*255,b*255,a*255),16)
  89. return color