1
2
3 import nuke, nukescripts
4 import random
5 import os
6 import textwrap
7
8
31
32
34 """Connects the selected node to the given viewer input index, ignoring errors if no node is selected."""
35
36 selection = None
37 try:
38 selection = nuke.selectedNode()
39 except ValueError:
40 pass
41
42 if selection is not None and selection.Class() == 'Viewer':
43 selection = None
44
45 nuke.connectViewer(inputIndex, selection)
46
47
49 """Toggles monitor output (switches it on if it's off, or vice versa) for the currently active viewer."""
50 viewer = nuke.activeViewer()
51 if viewer is not None:
52 enableKnob = viewer.node().knob('MonitorOutEnable')
53 enableKnob.setValue(not enableKnob.value())
54
55
63
64
66 """Returns a random message for use as an untitled script name.
67 Can be assigned to nuke.untitled as a callable.
68 Put a goofy_title.txt somewhere in your NUKE_PATH to customise."""
69
70 goofyFile = None
71 for dir in nuke.pluginPath():
72 fileName = os.path.join(dir, "goofy_title.txt")
73 if os.path.exists(fileName):
74 goofyFile = fileName
75 break
76
77 if goofyFile is None:
78 return "Missing goofy_title.txt"
79
80 file = open(goofyFile)
81 lines = file.readlines()
82 file.close()
83
84 lines = [line.strip() for line in lines]
85 lines = [line for line in lines if len(line) > 0 and line[0] != '#']
86
87 if len(lines) < 1:
88 return "Empty goofy_title.txt"
89
90 return random.choice(lines)
91
92
104
105
131
132
140
141
143 """
144 Returns a list of all currently active callbacks, with the following optional
145 arguments:
146 verbose=False : prints the documentation as well as the callback
147 callbackTypes=None : limit the callback info to a particular callback
148 type (e.g. ['OnCreates'])
149 """
150
151 all_Callback_Types = [ 'onUserCreates',
152 'onCreates',
153 'onScriptLoads',
154 'onScriptSaves',
155 'onScriptCloses',
156 'onDestroys',
157 'knobChangeds',
158 'updateUIs',
159 'autolabels',
160 'beforeRenders',
161 'beforeFrameRenders',
162 'afterRenders',
163 'afterFrameRenders',
164 'renderProgresses',
165 'filenameFilters',
166 'validateFilenames',
167 'autoSaveFilters',
168 'autoSaveRestoreFilters',
169 'autoSaveDeleteFilters',
170 ]
171
172
173 is_valid_type = (type(callbackTypes) is dict) or (type(callbackTypes) is list)
174 if ( not callbackTypes or (not is_valid_type ) ):
175 callbackTypes = all_Callback_Types
176
177 callback_defs = {}
178
179 for callbackType in callbackTypes:
180 callback_defs[callbackType] = eval('nuke.%s' %(callbackType))
181
182
183 maxTargetNameLen = max( map( len,' '.join( [ (k+'').join( callback_defs[k].keys() ) for k in callback_defs.keys() ] ).split(' ') ) )
184
185 indent = (maxTargetNameLen+8)*' '
186
187 sortedCallbackTypes = sorted( callback_defs.keys() )
188 for callbackType in sortedCallbackTypes:
189 for callbackTarget in callback_defs[callbackType].keys():
190 for func, a, b, c in callback_defs[callbackType][callbackTarget]:
191 id = '%s%s%s : '%(callbackType[:-1],'_'*(maxTargetNameLen-len(callbackType)-len(callbackTarget)+1),callbackTarget)
192 print '%s%s' %(id, func.__name__)
193 if verbose:
194 doc = func.__doc__
195 if not doc:
196 doc='NO DOCUMENTATION'
197 docNoReturns = str(doc).lstrip().replace('\n','')
198 docNoConsecutiveSpaces = " ".join(docNoReturns.split())
199 docWrappedText = textwrap.wrap(docNoConsecutiveSpaces, 60)
200 for line in docWrappedText:
201 print indent + line.replace('\n', '\n' + indent)
202