7 Replies Latest reply on Nov 17, 2015 11:14 AM by timkognito

    Wait until Snapshot ist applied

    timkognito

      Hi,

       

      I'm still working with SDK5. My plugin iterates through an array of photos, creates virtual copies and applies a develop-snapshot to each copy.

      How can I wait until LR has realy applied the developsnapshot before continue with the next photo in the array?

       

      Kind regards,

      Tim

        • 1. Re: Wait until Snapshot ist applied
          johnrellis Most Valuable Participant

          I believe you're referring to develop presets, rather than snapshots?

           

          Can you provide more details about what you've observed when invoking photo:applyDevelopPreset()? Why do you need to wait for the settings to actually be applied?

           

          My Export LUT plugin imports a synthetic image, applies some develop settings, and then exports the result.  I have observed that it can take a couple of seconds sometimes after invoking photo:applyDevelopPreset() before the changed settings are visible to photo:getDevelopSettings().  However, I haven't actually observed that the subsequent export fails to use the new develop settings.  It may well be that actions like exporting wait until the new settings are actually applied.  Thus, it would help all of us if you could provide more details.

           

          That all being said, my plugin uses the following code to wait until the photo:getDevelopSettings() returns the develop settings that were just applied by photo:applyDevelopPreset():

           

          --[[----------------------------------------------------------------------------
          public void
          apply (LrPhoto photo, LrDevelopPreset or LrPhoto presetOrPhoto)
          
          
          Applies the develop settings in "presetOrPhoto" to "photo", waiting for
          them to "settle down". Apparently it can take a small amount of time for
          them to actually be stable. "presetOrPhoto" can be either an
          LrDevelopPreset or a photo, whose develop settings will be applied to
          "photo". 
          ------------------------------------------------------------------------------]]
          
          
          function Preset.apply (photo, presetOrPhoto)
              local settings = presetAllowedSettings (presetOrPhoto)
             
              local preset = LrApplication.addDevelopPresetForPlugin (
                          _PLUGIN, "preset", settings)
          
                  --[[ Actually apply the preset and wait until the settings in
                  the preset equal the settings of the photo ]]
              catalog:withWriteAccessDo ("Export LUT: apply preset",
                  function () photo:applyDevelopPreset (preset, _PLUGIN) end,
                  {timeout = 15})
             
              local presetSettings = preset:getSetting ()
              local i = 0
              while i < 10 do
                  local photoSettings = photo:getDevelopSettings ()
                  local nonEqualKey, nonEqualValue = nil
                  for k, _ in pairs (presetSettings) do
                      if not Util.deepEqual (presetSettings [k], photoSettings [k]) then
                          nonEqualKey, nonEqualValue = k, photoSettings [k]
                          end
                      end
                  if nonEqualKey == nil then break end
                  i = i + 1
                  Debug.lognpp ("applyDevelopSettings waiting", i, nonEqualKey,
                      presetSettings [nonEqualKey], nonEqualValue)
                  LrTasks.sleep (0.25)
                  end
              end
          

           

          I've observed that sometimes it can take 10 iterations through the loop (2.5 seconds), waiting for photo:getDevelopSettings() to return the newly applied settings. The function Util.deepEqual (x, y) returns true if x == y or, if x and y tables, they have the same number of key/value pairs and the pairs are deepEqual().

          • 2. Re: Wait until Snapshot ist applied
            johnrellis Most Valuable Participant
            I've observed that sometimes it can take 10 iterations through the loop (2.5 seconds), waiting for photo:getDevelopSettings() to return the newly applied settings.

            I should add that I very infrequently observed this in LR 5, but I haven't observed this in LR 6 / CC 2015.  That doesn't mean it doesn't happen.

            • 3. Re: Wait until Snapshot ist applied
              timkognito Level 1

              johnrellis schrieb:

               

              I believe you're referring to develop presets, rather than snapshots?

              Hi John,

               

              no, I refer to the (undocumented) functions LrPhoto.getDevelopSnapshots() and LrPhoto.applyDevelopSnapshots()

              Both functions work, but applyDevelopSnapshots only works in the development-module.

               

              My code looks like this (it's a little bit shortened, because in my plugin it's spread over some more functions):

              for k, photo in pairs(aphotos) do
              
                  -- checkout, if there realy exist a snapshot
                  local asnapshots= photo:getDevelopSnapshots()
                  if asnapshots ~= nil then
                     
                      -- select only one photo
                      catalog:setSelectedPhotos(photo, {})
                     
                      for key, snapshot in pairs(asnapshots) do
                          -- create virtual copy
                          local virtualphoto= catalog:createVirtualCopies(snapshot["name"])
                          if virtualphoto ~= nil then
                              -- apply DevelopSnapshot
                              virtualphoto[1]:applyDevelopSnapshot(snapshot["snapshotID"])
                             
                              -- at this point, I want to wait until LR has done all the processing and really
                              -- has applied the snapshots setting
                          end
                      end
                     
                  end
                 
              end
              
              

               

              At line 15 I apply the virtual snapshot. LR starts working and applies the snapshot-settings to the photo. I would like to wait, until LR's calculations are done, but instead my slope continues with the next snapshot.

              • 4. Re: Wait until Snapshot ist applied
                johnrellis Most Valuable Participant
                I refer to the (undocumented) functions LrPhoto.getDevelopSnapshots() and LrPhoto.applyDevelopSnapshots()

                Got it, I forgot about those.

                 

                The method I posted above, spin-looping until the develop settings are actually applied, won't work for snapshots, because there doesn't appear to be any method (documented or not) for getting the develop settings of a snapshot.  I double-checked my list of all modules, functions, classes, and methods (documented or not) that I generate for each new version of Lightroom.


                So that raises the question of what symptoms you're observing that indicate that the snapshot settings aren't immediately getting applied and the deeper reasons why you'd like to avoid those symptoms -- there might be another way to reach the same ultimate goal.

                • 5. Re: Wait until Snapshot ist applied
                  timkognito Level 1

                  Hi John,

                   

                  for a better understanding a short description, how my plugin works:

                  1. check for all selected photos, if there are any snapshots
                  2. for every snapshot of a photo create a virtual copy with the name of the snapshot
                  3. for every virtual copy apply the proper snapshot

                   

                  My computer is a little bit slow. If a snapshot is applied, it takes 10-20 seconds until the snapshot-settings are calculated/applied/take affect and are visible (even if I do this from gui). I think this is normal (for slow computers ;-)

                   

                  My "problem" is, that the function call to LrPhoto.applyDevelopSnapshots() does not halt my slope until calculations are done. Instead the slope continues with the next photo/virtual copies/snapshots until all selected photos are processed and the progressbar has completed. I show a dialog to the user to say that the plugin has finished it's work, but this is not realy true, because LR is still processing the snapshots.

                   

                  Kind regards,

                  Tim

                  • 6. Re: Wait until Snapshot ist applied
                    johnrellis Most Valuable Participant
                    My "problem" is, that the function call to LrPhoto.applyDevelopSnapshots() does not halt my slope until calculations are done. Instead the slope continues with the next photo/virtual copies/snapshots until all selected photos are processed and the progressbar has completed. I show a dialog to the user to say that the plugin has finished it's work, but this is not realy true, because LR is still processing the snapshots.

                    Interesting.  After your plugin completes, what happens if you select one of the photos and open it in Develop?  Does it always show the changes from the applied snapshot?  In general, when you make changes to batches of photos with LR, it will often apply the changes asynchronously (in background), but you can continue to use the application interactively.

                     

                    I've experienced similar symptoms with LR Export. I have an export preset that invokes a Photoshop action as a post-process action, and when I invoke it on dozens of photos, the progress bar will show that the export has completed, even though LR can take many more minutes to finish invoking the Photoshop action in background.

                     

                    Offhand, I can't think of any way to better handle the problem, other than to warn the users that it could take a while for LR to finish updating the thumbnails. 

                    • 7. Re: Wait until Snapshot ist applied
                      timkognito Level 1
                      Interesting.  After your plugin completes, what happens if you select one of the photos and open it in Develop?  Does it always show the changes from the applied snapshot?  In general, when you make changes to batches of photos with LR, it will often apply the changes asynchronously (in background), but you can continue to use the application interactively.

                      Yes (applyDevelopSnapshots() only works in develop-mode), after LR has done it's work, every copy has applied it's snapshot.