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

Source Code for Module nukescripts.script

  1  # Copyright (c) 2009 The Foundry Visionmongers Ltd.  All Rights Reserved. 
  2   
  3  import os.path 
  4   
  5  import nuke 
  6  import nukescripts 
  7   
  8  kCommandField = 'Command:' 
  9  last_cmd = '' 
 10   
11 -def script_command(default_cmd):
12 global last_cmd 13 p = nuke.Panel("Nuke") 14 if (default_cmd != None and len(default_cmd) != 0): 15 use_cmd = default_cmd 16 else: 17 use_cmd = last_cmd 18 p.addScriptCommand(kCommandField, use_cmd) 19 p.addButton("Cancel") 20 p.addButton("OK") 21 result = p.show() 22 if result == 1: 23 last_cmd = p.value(kCommandField) 24 p.execute(kCommandField)
25 26 27
28 -def script_version_up():
29 """Adds 1 to the _v## at the end of the script name and saves a new 30 version.""" 31 root_name = nuke.toNode("root").name() 32 (prefix, v) = nukescripts.version_get(root_name, "v") 33 if v is None: return 34 35 v = int(v) 36 newFileName = nukescripts.version_set(root_name, prefix, v, v + 1) 37 38 newVersionExists = os.path.exists( newFileName ) 39 if newVersionExists: 40 message = "The script version \n%s" % newFileName 41 message += "\nalready exists.\nDo you want to overwrite it?" 42 cancelVersionUp = not nuke.ask( message ) 43 if cancelVersionUp: 44 return 45 46 nuke.scriptSaveAs(newFileName) 47 if nuke.env['studio']: 48 from hiero.ui.nuke_bridge.nukestudio import addNewScriptVersionToBin 49 addNewScriptVersionToBin(root_name, newFileName)
50 51
52 -def script_and_write_nodes_version_up():
53 """ Increments the versioning in the script name and the path of the timeline 54 write nodes, then saves the new version. """ 55 # Helper function to select/deselect a list of nodes 56 def _setNodesSelected(nodes, selected): 57 for node in nodes: 58 node.setSelected(selected)
59 60 kTimelineWriteNodeKnobName = "timeline_write_node" 61 # First clear the existing selection 62 existingSelection = nuke.selectedNodes() 63 _setNodesSelected(existingSelection, False) 64 65 writeNode = None 66 67 # Get the Studio write Node and version up 68 timelineWriteNodeKnob = nuke.root().knob(kTimelineWriteNodeKnobName) 69 if timelineWriteNodeKnob is not None: 70 timelineWriteNodeName = timelineWriteNodeKnob.getText() 71 writeNode = nuke.toNode(timelineWriteNodeName) 72 if writeNode is not None: 73 _setNodesSelected([writeNode], True) 74 75 # Version up 76 nukescripts.version_up() 77 nukescripts.script_version_up() 78 79 # Deselect the Write nodes and restore the existing selection 80 if writeNode is not None: 81 _setNodesSelected([writeNode], False) 82 _setNodesSelected(existingSelection, True) 83 84
85 -def get_script_data():
86 activechans = nuke.Root.channels() 87 totchan = len(activechans) 88 89 root = nuke.toNode("root") 90 rez = root.knob("proxy").value() 91 92 numnodes = len(nuke.allNodes()) 93 94 chaninuse = totchan 95 chanleft = 1023-totchan 96 memusage = nuke.cacheUsage()/1024/1024 97 output = "Script : "+root.name()+"\n" 98 output = output+"Total nodes: "+str(numnodes)+"\n" 99 if rez: 100 output = output+"\nResolution : --PROXY--\n" 101 else: 102 output = output+"\nResolution : **FULL RES**\n" 103 output += "\nElements:\n"+nukescripts.get_reads("long") 104 105 output += "\nChannels in use: "+str(totchan)+"\n" 106 output += "Channels left: "+str(chanleft)+"\n" 107 output += "\nCache Usage: "+str(memusage)+" mb\n" 108 output += "\nChannel Data :\n" 109 110 layers = nuke.Root.layers() 111 for i in layers: 112 output += "\n"+i.name()+"\n" 113 channels = i.channels() 114 for j in channels: 115 if j in activechans: 116 output += "\t"+j+"\n" 117 118 return output
119 120
121 -def script_data():
122 nuke.display("nukescripts.get_script_data()", nuke.root())
123
124 -def script_directory():
125 return nuke.script_directory()
126