Skip to main content
Inspiring
July 23, 2024
Answered

SDK how to make an image to be shown in the Develop module

  • July 23, 2024
  • 1 reply
  • 364 views

Being somewhere in the Library module, I want a certain image to be show / active in the Develop module.

 

The code below works as long as the image to be shown is in the grid.
However, when the image is not in the active grid, then the Develop module reports "No photo selected".
Even though if I go back to the grid and select "All photographs" in the left panel, the image is the selected image with the white border.

The issue is that upon the start of this plug-in I want to show a specific image in the Develop module, however I have no glue which folder or collection is active at that moment.

 

local function showInDevelopModule(photo)
	catalog:setSelectedPhotos(photo, {})

	local moduleName = LrApplicationView.getCurrentModuleName()
	if (moduleName ~= "develop") then
		LrApplicationView.switchToModule("develop")
	end
end

LrFunctionContext.postAsyncTaskWithContext("test", function(context)
	local message = nil
	LrDialogs.attachErrorDialogToFunctionContext(context)


	local photo = catalog:findPhotoByUuid("0AFA8451-6DDD-4CF6-B537-DB1E9FB53A88")
	showInDevelopModule(photo)
end)

 

This topic has been closed for replies.
Correct answer johnrellis

catalog:setSelectedPhotos() can only set the selection to photos that are displayed in the current active sources (folders, collections, etc.). When you invoke it with a photo that isn't in the current active sources, the selection gets set to "none". 

 

The script below sets the current source to All Photographs before setting the selection. And then it sleeps for 0.2 seconds to let the user interface "settle down" -- if it doesn't sleep, then the subsequent setSelectedPhotos() will sometimes be ignored. This is just one of many undocumented circumstances where the SDK doesn't correctly handle asynchrony in the UI (my plugins are littered with calls to sleep()).

 

This script doesn't handle the case when the desired photo is buried in a collapsed stack. The SDK doesn't provide functions for expanding stacks. So the only workaround I can think of is to create a temporary collection containing just the photo, set the current active source to that collection, and then proceed.  Alternatively, the plugin could create a smart collection "All Photos" that is defined to include all photos, and it could set the smart collection to be the current source.  (Stacking is ignored in smart collections.)

 

 

local LrDialogs = import "LrDialogs"
local message = LrDialogs.message

local LrApplication = import "LrApplication"
local LrApplicationView = import "LrApplicationView"
local LrFunctionContext = import "LrFunctionContext"
local LrTasks = import "LrTasks"

local catalog = LrApplication.activeCatalog ()

local function showInDevelopModule(photo)
    catalog:setActiveSources({catalog.kAllPhotos})
    LrTasks.sleep (0.2)
    catalog:setSelectedPhotos(photo, {photo})
    LrApplicationView.switchToModule("develop")
end

LrFunctionContext.postAsyncTaskWithContext("test", function(context)
    LrDialogs.attachErrorDialogToFunctionContext(context)

    local photo = catalog:findPhotoByUuid("3A03DC9F-3273-48B6-AC33-45E09AE4596E")
    showInDevelopModule(photo)
end)

 

1 reply

johnrellis
johnrellisCorrect answer
Legend
July 23, 2024

catalog:setSelectedPhotos() can only set the selection to photos that are displayed in the current active sources (folders, collections, etc.). When you invoke it with a photo that isn't in the current active sources, the selection gets set to "none". 

 

The script below sets the current source to All Photographs before setting the selection. And then it sleeps for 0.2 seconds to let the user interface "settle down" -- if it doesn't sleep, then the subsequent setSelectedPhotos() will sometimes be ignored. This is just one of many undocumented circumstances where the SDK doesn't correctly handle asynchrony in the UI (my plugins are littered with calls to sleep()).

 

This script doesn't handle the case when the desired photo is buried in a collapsed stack. The SDK doesn't provide functions for expanding stacks. So the only workaround I can think of is to create a temporary collection containing just the photo, set the current active source to that collection, and then proceed.  Alternatively, the plugin could create a smart collection "All Photos" that is defined to include all photos, and it could set the smart collection to be the current source.  (Stacking is ignored in smart collections.)

 

 

local LrDialogs = import "LrDialogs"
local message = LrDialogs.message

local LrApplication = import "LrApplication"
local LrApplicationView = import "LrApplicationView"
local LrFunctionContext = import "LrFunctionContext"
local LrTasks = import "LrTasks"

local catalog = LrApplication.activeCatalog ()

local function showInDevelopModule(photo)
    catalog:setActiveSources({catalog.kAllPhotos})
    LrTasks.sleep (0.2)
    catalog:setSelectedPhotos(photo, {photo})
    LrApplicationView.switchToModule("develop")
end

LrFunctionContext.postAsyncTaskWithContext("test", function(context)
    LrDialogs.attachErrorDialogToFunctionContext(context)

    local photo = catalog:findPhotoByUuid("3A03DC9F-3273-48B6-AC33-45E09AE4596E")
    showInDevelopModule(photo)
end)

 

Inspiring
July 24, 2024

Thank you again. Learning every day new things.