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

Source Code for Module nukescripts.create

  1  # Copyright (c) 2009 The Foundry Visionmongers Ltd.  All Rights Reserved. 
  2   
  3  import nuke 
  4  import os 
  5   
6 -def create_curve():
7 root = nuke.toNode("root") 8 curve_name = nuke.getInput("New curve name", "f") 9 if curve_name is not None: 10 if not len(curve_name) > 0: 11 nuke.message("Curve name can't be blank.") 12 else: 13 curve_knob = root.knob(curve_name) 14 if curve_knob is None: 15 root.addKnob(nuke.Double_Knob(curve_name, curve_name)) 16 nuke.animation("root."+curve_name, "expression", ("",))
17 18
19 -def create_read(defaulttype="Read"):
20 '''Create a Read node for a file selected from the file browser. 21 If a node is currently selected in the nodegraph and it has a 'file' 22 (or failing that a 'proxy') knob, the value (if any) will be used as the default 23 path for the file browser.''' 24 # Get the selected node, and the path on it's 'file' knob if it 25 # has one, or failing that, it's 'proxy' node, if it has that. 26 sel_node = None 27 default_dir = None 28 try: 29 sel_node = nuke.selectedNode() 30 except: 31 pass 32 if ( sel_node is not None ) and ( sel_node != '' ): 33 if 'file' in sel_node.knobs(): 34 default_dir = sel_node['file'].value() 35 if (default_dir == None or default_dir == '') and 'proxy' in sel_node.knobs(): 36 default_dir = sel_node['proxy'].value() 37 38 # Revert default_dir to None if it's empty so that the file browser 39 # will do it's default unset behaviour rather than open on an empty path. 40 if default_dir == '': default_dir = None 41 42 # Raise the file browser and get path(s) for Read node(s). 43 files = nuke.getClipname( "Read File(s)", default=default_dir, multiple=True ) 44 if files != None: 45 maxFiles = nuke.numvalue("preferences.maxPanels") 46 n = len(files) 47 for f in files: 48 isAbc = False 49 stripped = nuke.stripFrameRange(f) 50 nodeType = defaulttype 51 if isAudioFilename( stripped ): 52 nodeType = "AudioRead" 53 if isGeoFilename( stripped ): 54 nodeType = "ReadGeo2" 55 if isAbcFilename( stripped ): 56 isAbc = True 57 if isDeepFilename( stripped ): 58 nodeType = "DeepRead" 59 60 # only specify inpanel for the last n nodes. Old panels are kicked out using 61 # a deferred delete, so reading large numbers of files can internally build 62 # large numbers of active widgets before the deferred deletes occur. 63 useInPanel = True 64 if (maxFiles != 0 and n > maxFiles): 65 useInPanel = False 66 n = n-1 67 68 if isAbc: 69 nuke.createScenefileBrowser( f, "" ) 70 else: 71 try: 72 nuke.createNode( nodeType, "file {"+f+"}", inpanel = useInPanel) 73 except RuntimeError, err: 74 nuke.message(err.args[0])
75
76 -def isGeoFilename(filename):
77 filenameLower = filename.lower() 78 _, ext = os.path.splitext( filenameLower ) 79 80 if ext in ['.fbx', '.obj']: 81 return True 82 else: 83 return False
84
85 -def isAbcFilename(filename):
86 filenameLower = filename.lower() 87 _, ext = os.path.splitext( filenameLower ) 88 89 if ext in ['.abc']: 90 return True 91 else: 92 return False
93
94 -def isDeepFilename(filename):
95 filenameLower = filename.lower() 96 _, ext = os.path.splitext( filenameLower ) 97 98 if ext in ['.dtex', '.dshd', '.deepshad']: 99 return True 100 else: 101 return False
102
103 -def isAudioFilename(filename):
104 filenameLower = filename.lower() 105 _, ext = os.path.splitext( filenameLower ) 106 107 if ext in ['.wav', '.wave', '.aif', '.aiff']: 108 return True 109 else: 110 return False
111
112 -def create_viewsplitjoin():
113 views = nuke.views() 114 if len(views) < 2: 115 nuke.message("Only one view, nothing to split and rejoin.") 116 return 117 118 sel = nuke.selectedNode() 119 if sel == None: 120 nuke.message("You need to select a node to split views from and rejoin.") 121 return 122 123 nodes = [] 124 for i in views: 125 n = nuke.createNode("OneView", inpanel=False) 126 n.knob("label").setValue(i) 127 nodes.append(n) 128 129 selx = sel.knob("xpos").getValue() 130 sely = sel.knob("ypos").getValue() 131 132 join = nuke.createNode("JoinViews", inpanel=False) 133 134 for idx in range(0, len(nodes)): 135 nodes[idx].knob("view").setValue(idx+1) 136 nodes[idx].setInput(0, sel) 137 nodes[idx].knob("xpos").setValue(selx + idx * 100 - (len(nodes)-1)*50) 138 nodes[idx].knob("ypos").setValue(sely + 90) 139 join.setInput(idx, nodes[idx]) 140 141 join.knob("xpos").setValue(selx) 142 join.knob("ypos").setValue(sely+180)
143