[JW Lua] Batch Processor

Dave Foster fozder at me.com
Fri Jun 26 14:06:59 CEST 2015


Hello all,

I’ve written a basic batch processor, which applies selected JWLua scripts to all open documents (using demo code for file picker):

function openFiles()
    local dialog = finale.FCFileOpenDialog(finenv.UI())
    local windowtitle = finale.FCString()
    windowtitle.LuaString = "Choose plugins to run on all open files"
    dialog:SetWindowTitle(windowtitle)
    local filter = finale.FCString()
    filter.LuaString = "*.lua"
    local filterdescr = finale.FCString()
    filterdescr.LuaString = "Lua Files"
    dialog:AddFilter(filter, filterdescr)
    dialog.MultiSelect = true
    if dialog:Execute() then
        local filenames = finale.FCStrings()
        dialog:GetFileNames(filenames)
        return filenames
    end
end

local allDocuments = finale.FCDocuments()
allDocuments:LoadAll()
filenames = openFiles()
for doc in each(allDocuments) do
    doc:SwitchTo()
    finale.FCEntryMetrics.MarkMetricsForRebuild()
    finale.FCCellMetrics.MarkMetricsForRebuild()
    for fname in each(filenames) do
       print (fname.LuaString)
        local _file_to_execute = assert(loadfile(fname.LuaString))
        _file_to_execute()
    end
    doc:SwitchBack(true)
end

Is there any way to be able to apply this to an unopened folder of scores? I.E. how do you open a file, save it, then close it?

Cheers,

Dave



More information about the JWLua mailing list