Checking whether collection is smart
First of all - I'm just starting with Lua and LR SDK so please be indulgent with me 😉
My problem:
I am unable to determine whether a LrCollection object is a simple or smart collection.
LrCollection API provides a method collection:isSmartCollection() but I can't get it to work.
Hope you can help me to figure out what I am doing wrong.
My starting point:
A plugin that calls an external program to process the file(s) being handed over.
Upon return to LR, the resulting image file is added to the catalog.
I want to enhance the plugin so that the newly added file is also added to the collection from which the plugin was called, in case it was a collection.
The code I am using is as follows:
activeSourceIsCollection = nil
-- determine the source of the selected photo(s)
local activeSources = exportSession.catalog:getActiveSources()
-- Can there be more than 1 entry in this table??
-- I have no clue. But at least there is one, and this is the one we'll work with
activeSource = activeSources[1]
-- Check if it's a collection or a folder -> type must be 'table'
if (type(activeSource) == "table") and (activeSource:type() == "LrCollection") then
-- source is collection or smart collection
LrTasks.startAsyncTask (function()
activeSourceIsCollection = not activeSource:IsSmartCollection()
end)
end
...
if activeSourceIsCollection then
-- add to collection as well
exportSession.catalog:withWriteAccessDo( LOC "$$$/SNSHDR/Export/Import=Import tonemapped file",
function()
activeSource:addPhotos( { reimportedPhoto } )
end )
end
When the second if-stmt is encountered (which is several seconds after the AysncTask has been started, because in the meantime the external program was running) the activeSourceIsCollection is still untouched, meaning 'nil",
What am I doing wrong??
Thanks a lot for any hints and help.
Karsten