Lightroom SDK: add function to get a list of photos in the filmstrip

  • 3
  • Idea
  • Updated 4 years ago
Some plugins with background processing would like to visit all photos in the filmstrip (whether selected or not) for checking things and processing stuff.

Presently there is no way to do that (getTargetPhotos will return all photos in a filmstrip but only if none are selected).

Please correct me if there is a way to do this already which I've missed.

One can get a list of active (selected) sources contributing to the filmstrip, but without knowing the state of "include subfolders", and lib filters, and stacking... one can not reconstruct the filmstrip list.

See related topic in SDK forum: http://forums.adobe.com/message/39604...
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 382 Reply Likes

Posted 7 years ago

  • 3
Photo of john beardsworth

john beardsworth

  • 1042 Posts
  • 240 Reply Likes
Can't you dynamically set the selection in two steps? Use setSelectedPhotos to select the current image and then getMultipleSelectedOrAllPhotos which selects all if only one is selected.
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 382 Reply Likes
Almost, but not quite... - If one is willing to alter the user's selection for a moment (one must wait until the dust settles after setting one selected photo...), then one could use the getMultipleSelectedOrAllPhotos to retrieve the filmstrip. The trick is being able to do it without interfering with the user's work / selections...
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 382 Reply Likes
Maybe:

catalog:getFilmstripPhotos( options )


Actually, which photoset is desired depends on the objective of the plugin.

Some options would be required for some circumstances, e.g.:

- include those buried in stack.
- include those filtered out by library filters.

i.e. sometimes one wants just those the user sees, independent of what's selected (for background checking/processing of visible photos).

But sometimes one might want the buried items too (e.g. for operations that should permeate stacks). And sometimes one might want those that are presently invisible (being filtered out), e.g. - updating metadata used for a library filter or smart collection, which should be up-to-date so when user tweaks the lib-filters the metadata is ready...

Note: present function "photo-source":getPhotos has option to include-children.

PS - So far, my experience has been that I want include-children to be the same as the "Show Photos in Subfolders" setting, but I can't tell what that is. It also includes photos buried in collapsed stack, which has most-often been undesirable.
Photo of John R. Ellis

John R. Ellis, Champion

  • 3722 Posts
  • 973 Reply Likes
It appears that in 4.1, John's suggestion for getting all visible photos works "instantaneously" (atomically), without any delay visible to the user. I haven't testined in LR 3.

Here's the code fragment I used to test:

local selectedPhotos = catalog:getTargetPhotos ()
local selectedPhoto = catalog:getTargetPhoto ()
catalog:setSelectedPhotos (selectedPhoto, {})
local allVisiblePhotos = catalog:getMultipleSelectedOrAllPhotos ()
catalog:setSelectedPhotos (selectedPhoto, selectedPhotos)
Debug.pause (#allVisiblePhotos, #selectedPhotos,
#selectedPhotos == #catalog:getTargetPhotos ())
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 382 Reply Likes
I would really love to see two variations for this feature:

1. Get filmstrip photos, as filtered.
2. Get filmstrip photos, unfiltered.

Why? Sometimes one want's to do stuff to the photos as seen in filmstrip, but if the plugin needs to update metadata being used for filtering, it really needs to get unfiltered photos too.

My method for doing this now is:

cat:getFilmstripPhotos( assumeSubfoldersToo, ignoreIfBuried, metadataArray )

This method peruses photos from all active sources to come up with the array of photos to be returned. (unfortunately excludes special collection sources, like all-photographs, or missing photographs...).

The first parameter is only necessary since source:getPhotos demands it. What I really want is to have photos from subfolders if those photos are in the filmstrip, otherwise not.

The second parameter is because sometimes one wants to do things to buried photos too, and sometimes not.

The third parameter assures photos are included from source even if present lib filter includes a metadata column that is filtering them out.

This works OK, except:
* The target photos do not always match the intention, which can lead to the perception that the plugin is flaky, and rightfully so...
* It's slower than a native method would be.

So, maybe even two methods:
getFilmstripPhotos -- get's array of photos as seen in filmstrip
getSourcePhotos -- get's array of all photos from all selected sources, whether filtered, buried in stack, or whatever.

Those would provide the requisite primitives from which all else could be derived.

Sorry for verbosity.

Rob
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 382 Reply Likes
So far so good in Lr3 too (win7) - not yet tested on Mac. Here is the "finished" version:


--- Get photos visible in filmstrip (as filtered, as stacked, ... ).
--
-- @usage without disturbing user's present selection.
--
-- @return visiblePhotos (array) never nil, but may be empty (e.g. virgin catalog, empty folder/collection)
--
function Catalog:getVisiblePhotos()
-- works in Lr3+4/win7 - @23/Jan/2013 16:52, not tested on Mac ###1
local selectedPhotos = catalog:getTargetPhotos()
local selectedPhoto = catalog:getTargetPhoto()
if selectedPhoto then
catalog:setSelectedPhotos( selectedPhoto, {} )
local allVisiblePhotos = catalog:getMultipleSelectedOrAllPhotos()
catalog:setSelectedPhotos( selectedPhoto, selectedPhotos )
--Debug.pause( #allVisiblePhotos, #selectedPhotos, #selectedPhotos == #catalog:getTargetPhotos() )
return allVisiblePhotos
else
return selectedPhotos
end
end

The only potential problem I can see is if the user changes selection in the middle of this function, which would not be much worry if being run on demand by user-initiated menu function, but if being executed repeatedly in background loop it may be another story...

Needs more testing, but seems promising so far... - thanks John :-)

Rob
Photo of John R. Ellis

John R. Ellis, Champion

  • 3722 Posts
  • 973 Reply Likes
Are you saying that Catalog:getVisiblePhotos() doesn't work or Catalog:getFilmStripPhotos().
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 382 Reply Likes
getVisiblePhotos doesn't work, I assumed because of the difference in handling of special collections. What is getFilmStripPhotos()?
Photo of John R. Ellis

John R. Ellis, Champion

  • 3722 Posts
  • 973 Reply Likes
Any Filter uses the exact same logic to implement searching by "Visible photos only", and it appears to work when All Photographs is selected. I wonder what's different.

getFilmStripPhotos() was a function you described in an earlier post in this thread.
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 382 Reply Likes
Oops - I had it backwards: getVisiblePhotos works just fine. getFilmstripPhotos was the one with the problem. Thanks again John - you're the best :-)
Photo of John R. Ellis

John R. Ellis, Champion

  • 3722 Posts
  • 973 Reply Likes
That makes sense -- catalog:getActiveSources() still doesn't work:

http://feedback.photoshop.com/photosh...
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 382 Reply Likes
Beware: catalog:setSelectedPhotos adds a corresponding item to Undo menu, and so is inappropriate for background task - try to call only if necessary to avoid excessive 'Undo Select' entries on the undo stack.