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
142
143 """Returns a list of all currently active callbacks, with the following optional arguments:"""
144 """verbose=False : prints the documentation as well as the callback"""
145 """callbackTypes=None : limit the callback info to a particular callback type (e.g. ['OnCreates'])"""
146
147
148 all_Callback_Types = ['onUserCreates', 'onCreates', 'onScriptLoads', 'onScriptSaves', 'onScriptCloses', 'onDestroys', 'knobChangeds', 'updateUIs', 'autolabels', 'beforeRenders', 'beforeFrameRenders', 'afterRenders', 'afterFrameRenders', 'filenameFilters', 'validateFilenames', 'autoSaveFilters', 'autoSaveRestoreFilters', 'autoSaveDeleteFilters' ]
149
150
151 is_valid_type = (type(callbackTypes) is dict) or (type(callbackTypes) is list)
152 if ( not callbackTypes or (not is_valid_type ) ):
153 callbackTypes = all_Callback_Types
154
155 callback_defs = {}
156
157 for callbackType in callbackTypes:
158 callback_defs[callbackType] = eval('nuke.%s' %(callbackType))
159
160
161 maxTargetNameLen = max( map( len,' '.join( [ (k+'').join( callback_defs[k].keys() ) for k in callback_defs.keys() ] ).split(' ') ) )
162
163 indent = (maxTargetNameLen+8)*' '
164
165 sortedCallbackTypes = sorted( callback_defs.keys() )
166 for callbackType in sortedCallbackTypes:
167 for callbackTarget in callback_defs[callbackType].keys():
168 for func, a, b, c in callback_defs[callbackType][callbackTarget]:
169 id = '%s%s%s : '%(callbackType[:-1],'_'*(maxTargetNameLen-len(callbackType)-len(callbackTarget)+1),callbackTarget)
170 print '%s%s' %(id, func.__name__)
171 if verbose:
172 doc = func.__doc__
173 if not doc:
174 doc='NO DOCUMENTATION'
175 docNoReturns = str(doc).lstrip().replace('\n','')
176 docNoConsecutiveSpaces = " ".join(docNoReturns.split())
177 docWrappedText = textwrap.wrap(docNoConsecutiveSpaces, 60)
178 for line in docWrappedText:
179 print indent + line.replace('\n', '\n' + indent)
180