Lightroom SDK, Async task issue
I have a single diagnostic image, and am trying to export it with each of my many presets applied to it for the purpose of creating LUTs.
I'm trying to loop over all presets in all presets folders, and for each, reset any development settings on the current image, apply the current development preset, and then export the image with the preset name.
I have two issues with the code below. First, it seems to lag an image behind. For example, filename B.png will actually have preset A baked into it. Secondly, I get a stack overflow at some point during execution and am not sure why: I get "An internal error has occurred. ?:0: C stack overflow"
Really, I wish I didn't even have to do any of this with async tasks. This is a one time thing and I'd be happy to just have each preset export block. I added the absurdly long timeout because I was finding the main loop would run super fast and spawn all those async tasks, then most would fail since the first one seemed to be in the withWriteAccessDo call.
Any tips? Happy to do this another way...
local LrDialogs = import 'LrDialogs'
local LrLogger = import 'LrLogger'
local LrApplication = import 'LrApplication'
local LrTasks = import 'LrTasks'
local LrDevelopController = import 'LrDevelopController'
local LrExportSession = import 'LrExportSession'
local LrExportSettings = import 'LrExportSettings'
local LrFileUtils = import 'LrFileUtils'
local MyHWExportItem = {}
function MyHWExportItem.ExportForPreset( i_folder, i_preset )
local cat = LrApplication.activeCatalog()
LrTasks.startAsyncTask(function( )
cat:withWriteAccessDo("Custom plugin", function ( )
local presetname = i_preset:getName()
local photo = cat:getTargetPhoto()
-- Get the settings for the current develop preset
local presetSettings = i_preset:getSetting()
-- Turn off sharpening
presetSettings["Sharpness"] = 0
local tempLocalPreset = LrApplication.addDevelopPresetForPlugin(_PLUGIN, "", presetSettings)
-- Reset any prior adjustments
LrDevelopController.resetAllDevelopAdjustments()
-- Apply the new preset
photo:applyDevelopPreset( tempLocalPreset, _PLUGIN )
-- Configure the export
local settings = {}
settings["LR_export_destinationPathPrefix"] = "D:\\mtf.SynSync\\LUTS\\BakedNeutrals"
settings["LR_export_destinationPathSuffix"] = i_folder:getName()
settings["LR_tokenCustomString"] = i_preset:getName()
settings["LR_tokens"] = "{{custom_token}}"
-- Eliding some of these settings for the forum post. All just k/v
local pparams = {}
pparams["photosToExport"] = { photo }
pparams["exportSettings"] = settings
local export_session = LrExportSession( pparams )
-- Export to disk
export_session:doExportOnCurrentTask()
-- Before I added this long timeout, the loop would run
-- and almost instantly spawn all these async tasks for
-- all the presets. Then, they'd all run as fast as they
-- could, and fail b/c they couldn't get write access
-- to the catalog, I think...
end, { timeout = 100000 } )
end)
end
presetFolders = LrApplication.developPresetFolders()
for fi, i_folder in ipairs (LrApplication.developPresetFolders ()) do
for pi, i_preset in ipairs (i_folder:getDevelopPresets ()) do
MyHWExportItem.ExportForPreset(i_folder, i_preset)
end
end
