Copy link to clipboard
Copied
While importing photos from disk I'm struggling to stack these photos with existing photos in the Lightroom catalog.
My use case:
In my Lightroom catalog I have 2 images
On my disk I have 2 other images, noy yet loaded into Lightroom.
Their file name makes it clear which image on disk belongs to which image in the database
I'm using:
catalog:addPhoto( filePath, photo, 'above')
What works well?
The images are loaded into Lightroom.
What works not?
They are not stacked.
Question: what am I missing?
Steps to reproduce
I downloaded the images from Unsplash.com
local LrApplication = import "LrApplication"
local LrDialogs = import "LrDialogs"
local LrFileUtils = import "LrFileUtils"
local LrFunctionContext = import "LrFunctionContext"
local LrPathUtils = import "LrPathUtils"
local logFilename = "StackPhotos"
local myLogger = import 'LrLogger'( logFilename )
myLogger:enable( "logfile" )
local catalog = LrApplication.activeCatalog()
local function findByName(filename)
local foundPhoto = catalog:findPhotos {
searchDesc = {
criteria = "filename",
operation = "all",
value = LrPathUtils.replaceExtension(filename, "jpg"),
value2 = "",
}
}
return foundPhoto
end
local function main()
myLogger:info("Main: start")
--Import both photos WITH background in Lightroom: everyday_matters-closedEyes.jpg and Reinaldo Kevin.jpg
--Put in the directory of your chosing the 2 images without background: everyday_matters-closedEyes_nbg.png and Reinaldo Kevin_nbg.png
-- BTW _nbg stands for no background
local destinationPath = LrPathUtils.standardizePath("D:\\Temp\\Lightroom Burned Exports\\output")
myLogger:info("destinationPath", destinationPath)
-- Prepare database for adding photos
catalog:withWriteAccessDo ("Stack", function ()
-- Loop the folder with the image with no background
for filePath in LrFileUtils.directoryEntries( destinationPath ) do
-- Determine the file name of the original photo by removing the "_nbg"
local leafName = LrPathUtils.leafName(filePath:gsub("_nbg", ""))
local photo = findByName(leafName)[1]
if (photo) then
myLogger:info("Image found", leafName, photo, photo:getFormattedMetadata("fileName"))
catalog:addPhoto( filePath, photo, 'above')
else
myLogger:info("Image NOT found", leafName)
end
end
end)
LrDialogs.message("Stacking photos", "Finished stacking photos")
end
LrFunctionContext.postAsyncTaskWithContext ("Stack photos", function( context )
LrDialogs.attachErrorDialogToFunctionContext( context )
main()
end)
The log file
05/20/2024 16:18:37 INFO Main: start
05/20/2024 16:18:37 INFO destinationPath D:\Temp\Lightroom Burned Exports\output
05/20/2024 16:18:37 INFO Image found everyday_matters.png LrPhoto( id "126" ) everyday_matters.jpg
05/20/2024 16:18:39 INFO Image found Reinaldo Kevin.png LrPhoto( id "121" ) Reinaldo Kevin.jpg
It took me a bit of starting at this in the debugger to realize the problem: LR has this silly restriction that only photos in the same folder can be stacked (I've never understood the design rationale for that). If you place all four photos in the same folder and modify the script to only try to import photos ending with _nbg.jpg, then it works as desired.
Copy link to clipboard
Copied
It took me a bit of starting at this in the debugger to realize the problem: LR has this silly restriction that only photos in the same folder can be stacked (I've never understood the design rationale for that). If you place all four photos in the same folder and modify the script to only try to import photos ending with _nbg.jpg, then it works as desired.
Copy link to clipboard
Copied
Amazing and confirm, putting the images in the same folder as their "originals" allows one to add them to the stack.
How did you found out that they have to be in the same folder to be able to stack?
Reading the SDK documentation I didn't found it documented, but perhaps I looked in the wrong place???
Copy link to clipboard
Copied
Restricting stacking to photos in the same folder was a limitation I stumbled over when I migrated to LR 3 from Photoshop Elements Organizer, which didn't have that limitation:
Over the years, no one ever tried to justify this limitation.