1
1
function plugindef ()
2
+ finaleplugin .RequireDocument = false
2
3
finaleplugin .MinJWLuaVersion = 0.74
3
- finaleplugin .NoStore = false -- With RGP Lua 0.74 and higher, setting this to true causes all changes to rollback.
4
- finaleplugin .HandlesUndo = true -- A true value here does not suppress the automatic Undo logic in FCDocument.
4
+ -- A true value of NoStore causes all changes to be rolled back and prevent FCDocument instances from being saved.
5
+ finaleplugin .NoStore = false
6
+ -- A true value of HandlesUndo does not prevent the automatic Undo logic in FCDocument/FCLuaIterator from saving changes,
7
+ -- but it prevents other changes that are not protected by an explicit call to StartNewUndoBlock.
8
+ finaleplugin .HandlesUndo = true
5
9
finaleplugin .Notes = [[
6
- This script demonstrates how to process all open documents. The SwitchTo/SwitchBack functions automatically
7
- manage the Undo blocks per document, based on the NoStore setting.
10
+ This script demonstrates how to process all open documents or batch process a list of files with an iterator.
11
+ The SwitchTo/SwitchBack functions automatically manage the Undo blocks per document, based on the NoStore
12
+ and HandlesUndo settings. For versions of RGP Lua before 0.74, the Undo handling is not as consistent, and neither
13
+ FCLuaIterator nor FCDocument know about the NoStore or HandlesUndo settings.
8
14
]]
9
15
return " 0--process_all_documents.lua"
10
16
end
11
17
12
18
local shift_amount = 144
19
+ local use_iterator = true
20
+ local use_files = false
21
+ local files = (function ()
22
+ local retval = finale .FCStrings ()
23
+ local homepath = finale .FCString ()
24
+ homepath :SetUserPath ()
25
+ homepath :AssureEndingPathDelimiter ()
26
+ for _ , filename in ipairs ({ " Desktop/1.musx" , " Desktop/2.musx" }) do
27
+ local result = finale .FCString (homepath .LuaString .. filename )
28
+ retval :AddCopy (result )
29
+ end
30
+ return retval
31
+ end )()
13
32
14
33
local function file_name ()
15
34
local fpath = finale .FCString ()
@@ -19,10 +38,7 @@ local function file_name()
19
38
return fname .LuaString
20
39
end
21
40
22
- local docs = finale .FCDocuments ()
23
- docs :LoadAll ()
24
- for doc in each (docs ) do
25
- doc :SwitchTo (finale .FCString (file_name () .. " " .. doc .ID ), false )
41
+ local function process_document_with_name (doc , filepath )
26
42
local region = finale .FCMusicRegion ()
27
43
region :SetFullDocument ()
28
44
for entry in eachentrysaved (region ) do
@@ -31,5 +47,51 @@ for doc in each(docs) do
31
47
if not finaleplugin .NoStore then
32
48
region :Redraw () -- do not call Redraw when using NoStore, or you can get confusing visible artifacts.
33
49
end
34
- doc :SwitchBack (true ) -- true: changes successful (will be saved unless NoStore is true)
50
+ local filename = finale .FCString ()
51
+ filepath :SplitToPathAndFile (nil , filename )
52
+ print (" processed " .. filename .LuaString .. " [" .. doc .ID .. " ]" )
53
+ end
54
+
55
+ local function process_document (doc )
56
+ local filepath = finale .FCString ()
57
+ doc :GetPath (filepath )
58
+ process_document_with_name (doc , filepath )
35
59
end
60
+
61
+ local function move_expression_baseline ()
62
+ local baselines = finale .FCBaselines ()
63
+ baselines :LoadAllForPiece (finale .BASELINEMODE_EXPRESSIONABOVE )
64
+ local baseline = baselines :AssureSavedStaffForPiece (finale .BASELINEMODE_EXPRESSIONABOVE , 1 )
65
+ if baseline then
66
+ baseline .VerticalOffset = baseline .VerticalOffset + 24
67
+ baseline :Save ()
68
+ end
69
+ end
70
+
71
+ finenv .StartNewUndoBlock (" Explict changes" , false )
72
+
73
+ -- this change is suppressed if either NoStore or HandlesUndo is true
74
+ -- otherwise, it creates a separate undo entry
75
+ move_expression_baseline ()
76
+
77
+ if use_iterator then
78
+ local iterator = finale .FCLuaIterator ()
79
+ if use_files then
80
+ iterator :ForEachFileSaved (files , process_document_with_name )
81
+ else
82
+ iterator :ForEachDocument (process_document )
83
+ end
84
+ else
85
+ local docs = finale .FCDocuments ()
86
+ local count = docs :LoadAll ()
87
+ print (" got " .. count .. " documents" )
88
+ for doc in each (docs ) do
89
+ doc :SwitchTo (finale .FCString (file_name () .. " " .. doc .ID ), true ) -- true: save current changes
90
+ process_document (doc )
91
+ doc :SwitchBack (true ) -- true: changes successful (will be saved unless NoStore is true)
92
+ end
93
+ end
94
+
95
+ -- this change is suppressed if either NoStore or HandlesUndo is true
96
+ -- otherwise, it creates a separate undo entry
97
+ move_expression_baseline ()
0 commit comments