Skip navigation
Currently Being Moderated

change current selection to a subset of current selection

Feb 16, 2013 1:18 PM

Tags: #catalog #filmstrip #filenames #lua #selection_issues


I wonder how I can change/modify a current selection and then have 2 images selected for the new selection. I've got the full path of them 2 images (but I don't have their UUID).



From a given selection of images in the filmstrip (not a collection set) a plug-in retrieves full-paths-fileNames into a list for external processing (works fine).

Error handling: By mistake the user might include some images that should NOT be processed in the previous step. The first differring occurence of mistakenly selected image that should not be processed is caught by a simple comparison to the previous image. Both full-path-filenames are retrieved and displayed in an error message. Then plug-in stops further processing of selected images, Lightroom is back to where it started, the filmstrip selection remains unchanged.



What I want is that upon process stopping that the selection changes to the 2 images that were identified as different.

Actually differing occurences are caught by Labels and Ratings only.

if varFLabel ~= varFLabel_comp then


elseif varFRating ~= varFRating_comp then


Here is the relevant code I am working on:


LrTasks.startAsyncTask( function()
local photos = catalog:getTargetPhotos()
for j, photo in ipairs(photos) do
          varFLabel = photo:getFormattedMetadata('label')                    --word eg. approved
          varFRating = photo:getFormattedMetadata('rating')                    --number
          if lrItem > 1 then                    -- second pass of 'for ... do'
                    --catch missmatching Labels in selection by user
                    if varFLabel ~= varFLabel_comp then
                              LrDialogs.message(string.format("Labels missmatch!\n %q Not equal to %q", varFileName_comp, varFileName, "DIFF Labels", "info"), "Labels do NOT match!\nDouble-check your selection!\nStopping task and script!")
--new selection to show the two differing images in: varFileName_comp varFileName
                              return          --exit script
                    --catch missmatching Ratings in selection by user
                    elseif varFRating ~= varFRating_comp then
                              LrDialogs.message(string.format("Ratings missmatch!\n %q Not equal to %q", varFRating_comp, varFRating, "DIFF Ratings", "info"), "Ratings do NOT match!\nDouble-check your selection!\nStopping task and script!")
--new selection to show the two differing images in: varFileName_comp varFileName
                              return          --exit script
          --prepare for next comparison in 'for ... do' 
          varFileName_comp = varFileName
          varFLabel_comp = varFLabel
          varFRating_comp = varFRating


Tried to make use of the function setSelectedPhotos but I don't get any results only internal processing errors and don't know how to best proceed.

I assume this function requires the LrPhotoID derived from the selected Photos table (array).


photos = catalog:setSelectedPhotos( varFileName, varFileName_comp )


Edit: This command selects one of the differing images

return catalog:setSelectedPhotos( photo, {} ) --exit script


Hope someone can help.


Message was edited by: snahphoto

  • Currently Being Moderated
    Feb 16, 2013 3:12 PM   in reply to snahphoto
    Referring to the SDK documentation:
    catalog:setSelectedPhotos( activePhoto, otherSelectedPhotos )
    Sets the photo selection programmatically.

    First supported in version 3.0 of the Lightroom SDK.


    1. activePhoto
    (LrPhoto) The active photo; if multiple photos are selected, this is the brightest, "most selected" one.
    2. otherSelectedPhotos
    (table of LrPhoto) Additional photos to select.

    The first argument is an LrPhoto, and the second argument is an array of LrPhotos. In your example, the easiest way to get the LrPhotos is to remember them in variables as you iterate through the array of "photos" with the for loop, just as you do with varFLabel_comp and varFRating_comp.

    Mark as:
  • Currently Being Moderated
    Feb 16, 2013 4:20 PM   in reply to snahphoto

    If you maintain a second variable through the iteration, photo_comp, which is the value of "photo" from the previous iteration through the loop, then you could do:


    return catalog:setSelectedPhotos( varPhoto, {photo, photo_comp})

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points