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