• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

SDK how to stack images using catalog:addPhoto( filePath, photo, 'above')

Participant ,
May 20, 2024 May 20, 2024

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

  1. See the attached images
  2. Import the two photos without "_nbg" into Lightroom
  3. Put the other two, without "_nbg" in the file name, into some directory.
  4. Change in my sample code below my directory name with the directory name you used above.

 

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 

 

TOPICS
macOS , SDK , Windows

Views

122

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 20, 2024 May 20, 2024

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.

Votes

Translate

Translate
LEGEND ,
May 20, 2024 May 20, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2024 May 20, 2024

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???

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 20, 2024 May 20, 2024

Copy link to clipboard

Copied

LATEST

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:

https://community.adobe.com/t5/lightroom-classic-ideas/p-stacking-in-folders-and-collections-should-...

 

Over the years, no one ever tried to justify this limitation.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines