Package nukescripts :: Module misc
[hide private]
[frames] | no frames]

Source Code for Module nukescripts.misc

  1  # Copyright (c) 2009 The Foundry Visionmongers Ltd.  All Rights Reserved. 
  2   
  3  import nuke, nukescripts 
  4  import random 
  5  import os 
  6   
  7   
8 -def copy_knobs(args):
9 g1 = nuke.thisGroup() 10 selNodes = g1.selectedNodes() 11 12 g2 = nuke.nodes.Group(name = "____tempcopyknobgroup__") 13 with g2: 14 nuke.nodePaste(nukescripts.cut_paste_file()) 15 16 excludedKnobs = ["name", "xpos", "ypos"] 17 18 nodes = g2.nodes() 19 for i in g2.nodes(): 20 for j in selNodes: 21 k1 = i.knobs() 22 k2 = j.knobs() 23 intersection = dict([(item, k1[item]) for item in k1.keys() if item not in excludedKnobs and k2.has_key(item)]) 24 for k in intersection.keys(): 25 x1 = i[k] 26 x2 = j[k] 27 x2.fromScript(x1.toScript()) 28 29 nuke.delete(g2)
30 31
32 -def connect_selected_to_viewer(inputIndex):
33 """Connects the selected node to the given viewer input index, ignoring errors if no node is selected.""" 34 35 selection = None 36 try: 37 selection = nuke.selectedNode() 38 except ValueError: # no node selected 39 pass 40 41 if selection is not None and selection.Class() == 'Viewer': 42 selection = None 43 44 nuke.connectViewer(inputIndex, selection)
45 46
47 -def toggle_monitor_output():
48 """Toggles monitor output (switches it on if it's off, or vice versa) for the currently active viewer.""" 49 viewer = nuke.activeViewer() 50 if viewer is not None: 51 enableKnob = viewer.node().knob('MonitorOutEnable') 52 enableKnob.setValue(not enableKnob.value())
53 54
55 -def clear_selection_recursive(group = nuke.root()):
56 """Sets all nodes to unselected, including in child groups.""" 57 for n in group.selectedNodes(): 58 n.setSelected(False) 59 groups = [i for i in group.nodes() if i.Class() == 'Group'] 60 for i in groups: 61 clear_selection_recursive(i)
62 63
64 -def goofy_title():
65 """Returns a random message for use as an untitled script name. 66 Can be assigned to nuke.untitled as a callable. 67 Put a goofy_title.txt somewhere in your NUKE_PATH to customise.""" 68 69 goofyFile = None 70 for dir in nuke.pluginPath(): 71 fileName = os.path.join(dir, "goofy_title.txt") 72 if os.path.exists(fileName): 73 goofyFile = fileName 74 break 75 76 if goofyFile is None: 77 return "Missing goofy_title.txt" 78 79 file = open(goofyFile) 80 lines = file.readlines() 81 file.close() 82 83 lines = [line.strip() for line in lines] 84 lines = [line for line in lines if len(line) > 0 and line[0] != '#'] 85 86 if len(lines) < 1: 87 return "Empty goofy_title.txt" 88 89 return random.choice(lines)
90 91
92 -def declone(node):
93 if node.clones() == 0: 94 return 95 args = node.writeKnobs(nuke.WRITE_ALL | nuke.WRITE_USER_KNOB_DEFS | nuke.WRITE_NON_DEFAULT_ONLY | nuke.TO_SCRIPT) 96 newnode = nuke.createNode(node.Class(), knobs = args) 97 nuke.inputs(newnode, nuke.inputs(node)) 98 num_inputs = nuke.inputs(node) 99 for i in range(num_inputs): 100 newnode.setInput(i, node.input(i)) 101 node.setInput(0, newnode) 102 nuke.delete(node)
103 104
105 -def showname():
106 '''Shows the current script path and, if the selected node is a Read or Write node, the filename from it.''' 107 108 # get the nuke script path 109 # we always need this 110 nukescript = nuke.value("root.name") 111 112 # look if there is a selected node 113 # if not, output the script only 114 p = nuke.Panel("Current Info", 500) 115 try: 116 n = nuke.selectedNode() 117 if n.Class() == "Read" or n.Class() == "Write": 118 a = nuke.value(n.name()+".first", nuke.value("root.first_frame")) 119 b = nuke.value(n.name()+".last", nuke.value("root.last_frame")) 120 curfile = n.knob("file").value()+" "+str(a)+"-"+str(b) 121 p.addSingleLineInput("Filename", curfile) 122 p.addSingleLineInput("Script", nukescript) 123 p.show() 124 else: 125 p.addSingleLineInput("Script", nukescript) 126 p.show() 127 except: 128 p.addSingleLineInput("Script", nukescript) 129 p.show()
130 131
132 -def swapAB(n):
133 """Swaps the first two inputs of a node.""" 134 135 if max(n.inputs(), n.minimumInputs()) > 1: 136 a = n.input(0) 137 n.setInput(0, n.input(1)) 138 n.setInput(1, a)
139