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 nuke.createNode( nodeType, "file {"+f+"}", inpanel = useInPanel)
72
73 -def isGeoFilename(filename):
74 filenameLower = filename.lower() 75 _, ext = os.path.splitext( filenameLower ) 76 77 if ext in ['.fbx', '.obj']: 78 return True 79 else: 80 return False
81
82 -def isAbcFilename(filename):
83 filenameLower = filename.lower() 84 _, ext = os.path.splitext( filenameLower ) 85 86 if ext in ['.abc']: 87 return True 88 else: 89 return False
90
91 -def isDeepFilename(filename):
92 filenameLower = filename.lower() 93 _, ext = os.path.splitext( filenameLower ) 94 95 if ext in ['.dtex', '.dshd', '.deepshad']: 96 return True 97 else: 98 return False
99
100 -def isAudioFilename(filename):
101 filenameLower = filename.lower() 102 _, ext = os.path.splitext( filenameLower ) 103 104 if ext in ['.wav', '.wave', '.aif', '.aiff']: 105 return True 106 else: 107 return False
108
109 -def create_viewsplitjoin():
110 views = nuke.views() 111 if len(views) < 2: 112 nuke.message("Only one view, nothing to split and rejoin.") 113 return 114 115 sel = nuke.selectedNode() 116 if sel == None: 117 nuke.message("You need to select a node to split views from and rejoin.") 118 return 119 120 nodes = [] 121 for i in views: 122 n = nuke.createNode("OneView", inpanel=False) 123 n.knob("label").setValue(i) 124 nodes.append(n) 125 126 selx = sel.knob("xpos").getValue() 127 sely = sel.knob("ypos").getValue() 128 129 join = nuke.createNode("JoinViews", inpanel=False) 130 131 for idx in range(0, len(nodes)): 132 nodes[idx].knob("view").setValue(idx+1) 133 nodes[idx].setInput(0, sel) 134 nodes[idx].knob("xpos").setValue(selx + idx * 100 - (len(nodes)-1)*50) 135 nodes[idx].knob("ypos").setValue(sely + 90) 136 join.setInput(idx, nodes[idx]) 137 138 join.knob("xpos").setValue(selx) 139 join.knob("ypos").setValue(sely+180)
140