Advertisement
comp_V01

Duplicate with inputs

Sep 17th, 2018
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. '''
  2.  
  3. duplicateWithInputs V1.1
  4.  
  5. copyright 2018 Marcel Pichert
  6.  
  7. www.marcelpichert.com
  8.  
  9. '''
  10.  
  11. import nuke
  12. import nukescripts
  13.  
  14.  
  15.  
  16. def copyWithInputs():
  17.  
  18. #get selected nodes
  19.  
  20. global nodesWithInputs
  21.  
  22. nodesWithInputs = nuke.selectedNodes()
  23.  
  24.  
  25. def pasteWithInputs():
  26.  
  27. try:
  28. nodes = nodesWithInputs
  29.  
  30. except:
  31. nodes = "None"
  32.  
  33. #check if at least one node is selected
  34.  
  35. if len(nodes) != 0 and nodes != "None":
  36.  
  37. #duplicate nodes
  38.  
  39. newNodes = []
  40.  
  41. for n in nodes:
  42.  
  43. nuke.selectAll()
  44. nuke.invertSelection()
  45.  
  46. n.setSelected(True)
  47.  
  48. nukescripts.node_copypaste()
  49.  
  50. newNodes.append(nuke.selectedNode())
  51.  
  52.  
  53. #set variables
  54.  
  55. oldStartX = nodes[0].xpos()
  56. oldStartY = nodes[0].ypos()
  57.  
  58. newStartX = newNodes[0].xpos()
  59. newStartY = newNodes[0].ypos()
  60.  
  61.  
  62. #position new nodes
  63.  
  64. for i,x in enumerate(newNodes):
  65.  
  66. if i != 0:
  67.  
  68. offsetX = nodes[i].xpos() - oldStartX
  69. offsetY = nodes[i].ypos() - oldStartY
  70.  
  71. x.setXYpos(newStartX + offsetX, newStartY + offsetY)
  72.  
  73. #reconnect inputs
  74.  
  75. for s in range(nodes[i].inputs()):
  76.  
  77. try:
  78. inputNode = newNodes[nodes.index(nodes[i].input(s))]
  79.  
  80. except ValueError:
  81. inputNode = nodes[i].input(s)
  82.  
  83. x.setInput(s, inputNode)
  84.  
  85. x.setSelected(True)
  86.  
  87.  
  88. def duplicateWithInputs():
  89.  
  90. copyWithInputs()
  91.  
  92. pasteWithInputs()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement