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 version.""" 30 root_name = nuke.toNode("root").name() 31 (prefix, v) = nukescripts.version_get(root_name, "v") 32 if v is None: return 33 34 v = int(v) 35 newFileName = nukescripts.version_set(root_name, prefix, v, v + 1) 36 37 newVersionExists = os.path.exists( newFileName ) 38 if newVersionExists: 39 message = "The script version \n%s\nalread exists.\nDo you want to overwrite it?" % newFileName 40 cancelVersionUp = not nuke.ask( message ) 41 if cancelVersionUp: 42 return 43 44 nuke.scriptSaveAs(newFileName) 45 if nuke.env['studio']: 46 from hiero.ui.nuke_bridge.nukestudio import addNewScriptVersionToBin 47 addNewScriptVersionToBin(root_name, newFileName)
48 49
50 -def script_and_write_nodes_version_up():
51 """ Increments the versioning in the script name and the path of the timeline write nodes, then saves the new version. """ 52 # Helper function to select/deselect a list of nodes 53 def _setNodesSelected(nodes, selected): 54 for node in nodes: 55 node.setSelected(selected)
56 57 kTimelineWriteNodeKnobName = "timeline_write_node" 58 # First clear the existing selection 59 existingSelection = nuke.selectedNodes() 60 _setNodesSelected(existingSelection, False) 61 62 writeNode = None 63 64 # Get the Studio write Node and version up 65 timelineWriteNodeKnob = nuke.root().knob(kTimelineWriteNodeKnobName) 66 if timelineWriteNodeKnob is not None: 67 timelineWriteNodeName = timelineWriteNodeKnob.getText() 68 writeNode = nuke.toNode(timelineWriteNodeName) 69 if writeNode is not None: 70 _setNodesSelected([writeNode], True) 71 72 # Version up 73 nukescripts.version_up() 74 nukescripts.script_version_up() 75 76 # Deselect the Write nodes and restore the existing selection 77 if writeNode is not None: 78 _setNodesSelected([writeNode], False) 79 _setNodesSelected(existingSelection, True) 80 81
82 -def get_script_data():
83 activechans = nuke.Root.channels() 84 totchan = len(activechans) 85 86 root = nuke.toNode("root") 87 rez = root.knob("proxy").value() 88 89 numnodes = len(nuke.allNodes()) 90 91 chaninuse = totchan 92 chanleft = 1023-totchan 93 memusage = nuke.cacheUsage()/1024/1024 94 output = "Script : "+root.name()+"\n" 95 output = output+"Total nodes: "+str(numnodes)+"\n" 96 if rez: 97 output = output+"\nResolution : --PROXY--\n" 98 else: 99 output = output+"\nResolution : **FULL RES**\n" 100 output += "\nElements:\n"+nukescripts.get_reads("long") 101 102 output += "\nChannels in use: "+str(totchan)+"\n" 103 output += "Channels left: "+str(chanleft)+"\n" 104 output += "\nCache Usage: "+str(memusage)+" mb\n" 105 output += "\nChannel Data :\n" 106 107 layers = nuke.Root.layers() 108 for i in layers: 109 output += "\n"+i.name()+"\n" 110 channels = i.channels() 111 for j in channels: 112 if j in activechans: 113 output += "\t"+j+"\n" 114 115 return output
116 117
118 -def script_data():
119 nuke.display("nukescripts.get_script_data()", nuke.root())
120
121 -def script_directory():
122 return nuke.script_directory()
123