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