Skip to main content
ADrobkov
Known Participant
April 24, 2019
Question

Information about the previous photo in the directory/folder (if 1 file is selected)

  • April 24, 2019
  • 1 reply
  • 422 views

Hello! Thanks to your help, I figured out a lot and set up LR for myself. But still a lot of things I want to implement.

Question. I picked one photo from the library and I can see its metadata and information on the side. Can I get information about the metadata of the previous photo at this point?

local LrApplication = import("LrApplication")

local LrTasks = import("LrTasks")

local catalog = import("LrApplication").activeCatalog()

local LrBinding = import("LrBinding")

local LrFunctionContext = import("LrFunctionContext")

local LrProgressScope = import("LrProgressScope")

local LrPrefs = import("LrPrefs")

local prefs = LrPrefs.prefsForPlugin()

function showDialog(context)

  local props = LrBinding.makePropertyTable(context)

    local fillFormat = props.fillFormat

    prefs.fillFormat = fillFormat

    updateFill(fillFormat)

end

function updateFill(fillFormat)

  LrTasks.startAsyncTask(function()

    catalog:withWriteAccessDo("&Фиксация данных: \"STP\"", function()

      local photos = catalog.targetPhotos

      local countPhotos = #photos

      local ProgressBar = LrProgressScope({

        title = "Фиксация данных \"STP\" для " .. tostring(countPhotos) .. " файла(ов)"

      })

      for i, photo in ipairs(photos) do

local settings = photo:getDevelopSettings()

local typeColor = ''

local ConvertToGrayscale = (settings["ConvertToGrayscale"])

if ConvertToGrayscale == true then typeColor = 'M' else typeColor = 'C' end

photo:setRawMetadata("copyName", 'S'..typeColor)

        local previousversionFile = GETTING DATA WITH FIELD provider of the PREVIOUS FILE

versionFile = 1 + previousversionFile

photo:setRawMetadata("provider", versionFile)

photo:setRawMetadata("label", 'STP')

photo:setRawMetadata("location", 'Drive')

        local fileFormat = photo:getRawMetadata("fileFormat") or ""

if fileFormat == 'TIFF' then

photo:buildSmartPreview()

end

        ProgressBar:setPortionComplete(i, countPhotos)

      end

      ProgressBar:done()

    end)

  end)

end

LrFunctionContext.callWithContext("theName", showDialog)

Without this line "local previousversionFile = GETTING DATA WITH FIELD provider of the PREVIOUS FILE" everything works.

Here is an example of the code I want to use for file version numbering. To do this, I use the "provider"field. By default, for each photo in this field is set to 0. If I want to create a new version of processing with my hands, I create a virtual copy and run this code. I want to add it so that it took data from the provider field and added 1 and assigned this value to the current file. This can be done by selecting 2 files. But is it possible to do with one active selection (LR does not quickly process the selection and uploading of data if the selected photo is more than one).

Thanks in advance for your help

This topic has been closed for replies.

1 reply

johnrellis
Legend
April 24, 2019
This can be done by selecting 2 files. But is it possible to do with one active selection

To test my understanding: The user has selected exactly one photo in Library grid view. You want your plugin to find the photo that appears in grid view or the filmstrip immediately before that photo.

Assuming my understanding is correct, the plugin can get an array of all photos visible in the grid or filmstrip using this song-and-dance:

--[[----------------------------------------------------------------------------

array of LrPhoto

visiblePhotos ()

Returns an array of all currently visible photos in the grid or filmstrip. The

implementation seems fragile, working around a limitation in the SDK.  But it

seems to work.

------------------------------------------------------------------------------]]

function visiblePhotos ()

    local selectedPhotos = catalog:getTargetPhotos ()

    local selectedPhoto = catalog:getTargetPhoto ()

    if selectedPhoto == nil then return selectedPhotos end

    catalog:setSelectedPhotos (selectedPhoto, {})

    local allVisiblePhotos = catalog:getMultipleSelectedOrAllPhotos ()

    catalog:setSelectedPhotos (selectedPhoto, selectedPhotos)

    return allVisiblePhotos

    end  

The plugin can search that array for the currently selected photo and then choose the photo immediately before it in the array.