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

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

Participant ,
Jul 23, 2024 Jul 23, 2024

Copy link to clipboard

Copied

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)

 

TOPICS
macOS , SDK , Windows

Views

153

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 , Jul 23, 2024 Jul 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

...

Votes

Translate

Translate
LEGEND ,
Jul 23, 2024 Jul 23, 2024

Copy link to clipboard

Copied

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)

 

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 ,
Jul 23, 2024 Jul 23, 2024

Copy link to clipboard

Copied

LATEST

Thank you again. Learning every day new things.

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