7 Replies Latest reply on Jun 30, 2011 9:01 PM by areohbee

    Specifying ExportServiceProvider when Invoking Export

    jovenator Level 1

      I am trying to programatically kick off an export and I have looked all over but cannot figure out how to specify which export service provider to use in the export. exportSettings covers lots of stuff but not which ExportServiceProvider. This seems like it should be obvious.

        • 1. Re: Specifying ExportServiceProvider when Invoking Export
          jovenator Level 1

          I am using the following code and get an error that says AgExportSession: missing libraryFile argument. My assumption is this is because it can't figure out which ExportServiceProvider to call.



            function ()      

              local exportSession = LrExportSession({

                photosToExport = {},

                exportSettings = {}




          • 2. Re: Specifying ExportServiceProvider when Invoking Export
            areohbee Level 6

            You don't need an export service to kick off an export, but you probably do need some photos and/or settings...


            Here's a function to export a tif:


            function NxTooey.exportTif( photo, filename )


                if photo == nil then
                    error( "No photo to export as tif." )
                local photoPath = photo:getRawMetadata( 'path' )
                if RcFileUtils.existsAsFile( photoPath ) then
                    -- good
                    error( "Unable to export tif, file is missing: " .. photoPath )
                local params = {}
                params.LR_collisionHandling = 'rename' -- this should never happen - I'll be checking in case it does.
                params.LR_export_bitDepth = 16
                params.LR_export_colorSpace = prefs.tifColorSpace
                params.LR_export_destinationType = "sourceFolder"
                params.LR_export_useSubfolder = false
                params.LR_extensionCase = "lowercase"
                params.LR_format = "TIFF"
                params.LR_initialSequenceNumber = 1
                params.LR_jpeg_limitSize = 100
                params.LR_jpeg_quality = 1
                params.LR_jpeg_useLimitSize = false
                params.LR_metadata_keywordOptions = "lightroomHierarchical"
                params.LR_minimizeEmbeddedMetadata = false
                params.LR_outputSharpeningLevel = 2
                params.LR_outputSharpeningMedia = "screen"
                params.LR_outputSharpeningOn = false
                params.LR_reimportExportedPhoto = false
                params.LR_reimport_stackWithOriginal = false
                params.LR_reimport_stackWithOriginal_position = "below"
                params.LR_renamingTokensOn = true
                params.LR_size_doConstrain = false
                params.LR_size_resolution = 240
                params.LR_size_resolutionUnits = "inch"
                params.LR_tokenCustomString = ""
                params.LR_tokens = LrPathUtils.removeExtension( filename )
                params.LR_useWatermark = false
                params.LR_watermarking_id = "<simpleCopyrightWatermark>"
                local exportSession = LrExportSession {
                    photosToExport = { photo },
                    exportSettings = params,
                exportSession:doExportOnCurrentTask() -- block until all renditions are created.
                local exportedTif = nil
                for i, rendition in exportSession:renditions() do
                    local status, other = rendition:waitForRender()
                    if status then
                        -- good
                        exportedTif = other
                        break -- there's only one.
                        error( "Unable to create rendition, photo: " .. photoPath )
                return exportedTif

            • 3. Re: Specifying ExportServiceProvider when Invoking Export
              jovenator Level 1

              Got it. So instead of writing a custom ExportServiceProvider, I just put my custom code at the end and wait on the renditions?

              • 4. Re: Specifying ExportServiceProvider when Invoking Export
                areohbee Level 6

                I think when you define an export service Lightroom gives you an entry in the export drop down, and the corresponding sections in the export dialog box, and then when the user clicks the 'Export' button, Lightroom creates an export context containing an export session and a progress scope, then calls the process-rendered-photos function you have defined and passes it the export context. You call configure-progress and start rendering, then wait for renditions...


                If you start an export without an export service, there won't be an export context, because your plugin is the "export context". You create the progress scope, if you want one, and the whole mess is kicked off by your plugin via the export session you create.


                So, I think, if your plugin intiates the export, instead of the user, there won't be an export service provider involved.


                Put another way, an export service provider is not an object that is accessible by your plugin, rather its a table of callbacks you can define so in case the user initiates the export, Lightroom can involve your plugin via callbacks.


                i.e. if you define an "export service provider" in Info.lua, then Lightroom will do some stuff for you, if you don't then you have to do that stuff yerself.


                Minimum requirement for an export:

                - an export session with photos and settings.


                Either your plugin creates it or Lightroom creates it.


                But, once that export session is created, then your plugin needs to:

                - start rendering

                - wait for renditions.








                Clear as mud?


                • 5. Re: Specifying ExportServiceProvider when Invoking Export
                  jovenator Level 1

                  I have my export code working pretty well. One thing that I'd like to avoid is exporting the files and then processing them. It seems I should be able to export them in one thread and then process them in another. I thought that I could do this by calling exportSession:doExportOnNewTask() and then calling rendition:waitForRender() before processing each one. My assumption was that waitForRender() would blokc until the other thread had processed that photo. However, when I try this I get a strange error saying something about two threads calling the same code. Am I just misunderstanding how doExportOnNewTask() works?

                  • 6. Re: Specifying ExportServiceProvider when Invoking Export
                    jovenator Level 1

                    I tried it again and it works fine now. Maybe I messed something up the first time. Wouldnt be the first time.

                    • 7. Re: Specifying ExportServiceProvider when Invoking Export
                      areohbee Level 6

                      I may have contributed to your confusion:


                      in the example I posted above, the line:




                      is unnecessary / redundent.


                      Simply calling


                      exportSession:renditions() will start the export/rendering on an asynchronous task.


                      So, I think if one wants to process each rendition then one need not call do-export...


                      (historical note: export-session used to have a start-rendering method, which has disappeared, I think it became export-session:do-export-on-new-task).


                      Similarly, export-session:do-export-on-current-task starts-rendering but only returns after all photos have been completely rendered.