4 Replies Latest reply on Jun 11, 2015 10:14 PM by rdsm

    Publishing Smart Preview Catalogs to an online file Repository

    rdsm

      Hi,

      I am developing a lightroom plugin in lua which will allow me to upload/publish smart preview catalogs to an online file repository.

      So far I have been successful in uploading jpegs to the online repository.

      However, now I am facing difficulty in building the smart preview files.

       

      local cat

      LrTasks.startAsyncTaskWithoutErrorHandler ( function ()

          cat = catalog:buildSmartPreviews(photos)

      end,'randomName')


      The LrCatalog object that the below code snippet is returning has nil data type value when I am trying to display the output using LrDialogs.message() function.

        • 1. Re: Publishing Smart Preview Catalogs to an online file Repository
          johnrellis Most Valuable Participant

          In your code snippet, the return value for catalog:buildSmartPreviews() is a table, not an LrCatalog object.  See the documentation for catalog:buildingSmartPreviews ():

           

          (table of arrays) A table with sub-arrays indicating the result of the smart preview build attempt. The sub-arrays are 'created', 'existed', and 'failed', and they contain LrPhoto objects corresponding to the photos for which the indicated status is appropriate.

           

          Also, if the code looks like this:

           

          local cat
          LrTasks.startAsyncTaskWithoutErrorHandler (function ()
              cat = catalog:buildSmartPreviews (photos)
               end, 'randomName')
          LrDialogs.message (...cat...)
          

           

          Then the value of "cat" in line 5 may or may not have been assigned on line 3.  The task started on line 2 is an asynchronous thread that may not have even started execution when line 5 is reached.

           

          The SDK requires that many of its calls must be executed in tasks other than the main task.  One common technique is to run your entire plugin in a task, so that you don't have to worry (as much) about this requirement.;

          • 2. Re: Publishing Smart Preview Catalogs to an online file Repository
            rdsm Level 1

            Hi johnrellis,

            Thank you for your reply. You are correct, I believe that the message is popping up as soon as i click on publish and after that the asynchronous thread is getting executed.

            I wish to first store the LrPhoto object (which is I assume is the Smart Preview Catalog) in a variable and then upload it to the repository. It is given that the function

            catalog:buildSmartPreviews (photos)

            can only be called from within an async function. How do I go about ensuring that i first recieve the value of the variable and then publish it


            • 3. Re: Publishing Smart Preview Catalogs to an online file Repository
              johnrellis Most Valuable Participant

              Run your entire plugin code within a task:

               

              local function main ()
                  ...all the work of your plugin...
                end
              
              LrTasks.startAsyncTask (main, "main")
              
              

               

              Then this code within main() should work:

                  

              local result = catalog:buildSmartPreviews (photos)
              ...access the contents of 'result'...
              

               


              • 4. Re: Publishing Smart Preview Catalogs to an online file Repository
                rdsm Level 1

                Hi John,

                Thanks for helping me out..

                Putting the function

                exportServiceProvider.processRenderedPhotos( functionContext, exportContext )

                within the main function does not execute it.

                Also, its throwing an error when i put main inside processRenderedPhotos function.

                For the moment, I have used LrTasks.sleep() but I would have to change it during testing.

                Also,


                local photos = {}

                for i, rendition in exportContext:renditions { stopIfCanceled = true } do

                   local photo = rendition.photo

                   LrTasks.startAsyncTask(function ()

                   LrDialogs.message(type(photo:buildSmartPreview()),photo:buildSmartPreview(),"")

                   end)

                   LrTasks.sleep(3)

                   photo:deleteSmartPreview()

                   table.insert(photos, photo)

                end

                local catalog = exportSession.catalog

                local result=  {}

                local pic

                LrTasks.startAsyncTask(function ()

                   result = catalog:buildSmartPreviews( photos )

                   for key,value in pairs(result.created) do

                       LrDialogs.message("key number of result.created "..key,"type of value of result.created "..type(value),"Info")

                       pic = value

                       local picName = pic:getFormattedMetadata(fileName)

                       local picLocation = pic:getFormattedMetadata(filePath)

                       LrDialogs.message(picName,picLocation,"")

                   end

                end)

                LrTasks.sleep(3)

                 

                I guess the following is happening:-

                result = { "created" = { {} , {} .........} , "existed" = { {} , {} .........} , "failed" = { {} , {} .........} }

                the number of keys of result.created is coming correct but all of them have nil values.