1 """This module define the scriptSaveAndClear method for Nuke API.
2 nuke.scriptSaveAndClear will call nuke.scriptSave() if any changes were made and then calls nuke.scriptClear()
3 """
4
5 import nuke
6
8 """ scriptSaveAndClear(filename=None, ignoreUnsavedChanges=False) -> None
9 Calls nuke.scriptSave and nuke.scriptClear
10 @param filename: Save to this file name without changing the script name in the
11 project.
12 @param ignoreUnsavedChanges: Optional. If set to True scripSave will be called,
13 ignoring any unsaved changes
14 @return: True when sucessful. False if the user cancels the operation. In this
15 case nuke.scripClear will not be called
16 """
17
18 root = nuke.Root()
19 if not ignoreUnsavedChanges and root is not None and root.modified() and len(root.nodes()) > 0:
20
21 runScriptSave = False
22
23 if filename is None:
24 scriptName = ''
25 try:
26 scriptName = nuke.scriptName()
27 except RuntimeError:
28 scriptName = 'untitled'
29 try:
30 runScriptSave = nuke.askWithCancel( "Save changes to " + scriptName + " before closing?" )
31 except nuke.CancelledError:
32 return False
33 else:
34 runScriptSave = True
35
36 if runScriptSave:
37 try:
38 nuke.scriptSave( filename )
39 except RuntimeError:
40 return False
41
42 nuke.scriptClear()
43 return True
44