SDK Lightroom : Is it possible to retrieve photo array of kPreviousImport "collection"

  • 2
  • Question
  • Updated 9 months ago
  • (Edited)
Hi everyone, I hope this thread doesn't exist yet because i haven't found it on this forum.

I am trying to make a plugin in order to apply a batch treatment on photos that are actually viewed in lightroom depending the current view in the library tab.

So i wanted to use the catalog:getActiveSources() function in order to get the right folder or collection and get photos in them.

This function work very well with directory or classic collections, but when the current view in Lightroom is the Previous import one, the function returns to me : "previous_import" that is the value of the kPreviousImport constant. <br><br>Is there any possibilities to retreive photos contained in this "collection" ? We can't reach it with the different collection functions : catalog:getChildCollections(), catalog:getChildCollectionSets()<br><br>I even tried to find this "collection" using a loop and catalog:getCollectionByLocalIdentifier() function but with no result :(

The documentation of getActiveSources say :"
Retrieves currently viewed collections, collection sets, or folders.

First supported in version 3.0 of the Lightroom SDK.

Return value(table) Array of the currently viewed objects as LrCollectionLrCollectionSetLrPublishedCollectionLrPublishedCollectionSetLrFolder or one of the string constants defined in these LrCatalog properties:
  • kAllPhotos
  • kQuickCollectionIdentifier
  • kPreviousImport
  • kTemporaryImages
  • kLastCatalogExport

Thank you for your help
Photo of Calou


  • 2 Posts
  • 0 Reply Likes

Posted 9 months ago

  • 2
Photo of John R. Ellis

John R. Ellis, Champion

  • 5131 Posts
  • 1454 Reply Likes
"Previous Import" isn't a true collection.  photo:getContainedCollections() doesn't return it either.

I think the best you can do is this bizarre song-and-dance:

1. Save the current sources using catalog:getActiveSources().

2. Save the current view filter using catalog:getCurrentViewFilter().

3. Save the current selection using catalog:getTargetPhoto() to determine if any photos are selected, and if so, catalog:getTargetPhotos() to get those photos.

4. Change the active source to Previous Import using catalog:setActiveSources().

5. Clear the current view filter using catalog:setCurrentViewFilter().

6. Clear the current selection using LrSelection.selectNone().

7. Get the currently visible photos using catalog:getTargetPhotos().

8. Some of the photos from step 7 may be the tops of stacks that are collapsed (yes, you can stack photos in Previous Import).   So for each photo from step 7, if photo:getRawMetadata ("stackInFolderIsCollapsed") is true, then add the other stacked photos by calling photo:getRawMetadata ("stackInFolderMembers").

9. Restore the original sources using catalog:setActiveSources().

10. Restore the original view filter using catalog:setCurrentViewFilter().

11. Restore the original selection using catalog:setTargetPhotos() or LrSelection.selectNone() (photo:setTargetPhotos() can't set the empty selection).

Note that when setting selections, view filters, and active sources, sometimes it's necessary to have a polite spin loop that waits until the change actually "takes" (sleeping 0.05 secs each iteration).  My plugins are littered with these loops -- it's never been clear to me exactly where they're needed, so I add them as needed (clearly an architectural defect in the SDK).

Photo of Calou


  • 2 Posts
  • 0 Reply Likes
Thank you very much for your answer it works very well!