9 Replies Latest reply on Feb 13, 2016 12:04 PM by Griffel

    How to get photo data outside processRenderedPhotos?

    Griffel Level 1

      LR SDK is still new for me. I'm fixing some issues of an open source project. It's intended to export files to Wikimedia Commons from LR. There are two places, where it's needed to fill a text based formular by actual values of selected photos: (a) at export, (b) at export dialog there is an option to have a preview of the filled formular, only the first photo of the selection is needed. (b) can be called before (a).

      (a) works fine. An iteration is done, the context is availbale by the calling parameter "exportContext" of function "processRenderedPhotos". The "exportContext" is used to get the "exportSession".

      (b) is caused by a push button at "viewFactory:push_button" in "sectionsForTopOfDialog". There is neither an "exportContext" nor an "exportSession" available.

      Up to now I have no idea, to get data of a photo outside of "processRenderedPhotos", like at "sectionsForTopOfDialog".

      Thanks for your interest of this thread!

      Any help is appreciated.

      Another description of this issue I made recently here: here,

        • 1. Re: How to get photo data outside processRenderedPhotos?
          Griffel Level 1

          Maybe something like a call of LrApplication.activeCatalog(), followed by catalog:getTargetPhotos(), could be the solution?

          • 2. Re: How to get photo data outside processRenderedPhotos?
            johnrellis Most Valuable Participant

            Right, catalog:getTargetPhotos() returns the current selection of photos. 

            • 3. Re: How to get photo data outside processRenderedPhotos?
              Griffel Level 1

              johnrellis wrote:

               

              Right, catalog:getTargetPhotos() returns the current selection of photos.

              It seems, it depends of the context. I'm in a context of "sectionsForTopOfDialog", preparing a text.

              I tried:

                 local activeCatalog = LrApplication.activeCatalog()

                 local listOfPhotos = activeCatalog.getTargetPhotos()

              The first line works, the second one not.

              When I try to press the button to show a message box after the call of a function with these two lines, it works, if the first line is in the function.

              If the function has both lines, the button is inactive.

               

              • 4. Re: How to get photo data outside processRenderedPhotos?
                johnrellis Most Valuable Participant

                You need a colon, not a period, to invoke a method: activeCatalog:getTargetPhotos().

                 

                What's happening is that the task in which that code is running raised an assertion-failed error and terminated.  By default, such errors that arise from tasks other than the main task are ignored.   You can instrument all of your tasks to catch the error using LrDialogs.attachErrorDialogToFunctionContext (context).   Or you can use by Debugging Toolkit, which will take an hour or two to install and get up to speed, but it will quickly pay off.  Or you can look elsewhere in this forum for a recipe about how to use a full IDE debugger with the LR SDK.

                • 5. Re: How to get photo data outside processRenderedPhotos?
                  Griffel Level 1

                  John, thanks a lot for your help spending your time!

                   

                  I highly appreciate the background concerning task/assertion/error/termination!

                   

                  In the meantime I detected myself the error using a dot instead of a colon. It looks like, it's a common beginner error.
                  Now I will be able to continue my work, I stucked a long time at the point, not to know how to reach a photo of the selection outside any context.
                  It's caused by my still uncomplete overview of the SDK.

                   

                  I already tried your Debugging Toolkit (and I've seen your request at Adobe to provide a better LR SDK debugging support).
                  It took me a while to install the toolkit. As a result, I could do "run" and all I got to see have been static global variables. I was not able to find a "step command" or viewing the call stack or local variables.

                  Maybe, I missed something during installation, and finally I decided to revert the installation. Another argument is the character of the project:

                  I don't want to share the debugger and sources with debugger specific stuff with the projects version control system, to force other members of the development team or end users to use it.

                   

                  BTW, at your website you are stating "The Debugging Toolkit for the Lightroom versions 3–6 SDK", but at the HTML page in the zip file is still stated "3–5 SDK".

                  • 6. Re: How to get photo data outside processRenderedPhotos?
                    johnrellis Most Valuable Participant
                    I was not able to find a "step command" or viewing the call stack or local variables.

                    Yup, it's very rudimentary.  You can see the call stack when an error occurs.  And you can insert "breakpoints" by adding a line at the appropriate point with the variables you want to inspect:

                     

                    Debug.pause (docs, i, j)

                     

                    Since Lua loads immediately, the turnaround is instantaneous.  Most importantly, you can poke around values and data structures with a full-fledged "pretty printer" and expression evaluator.

                     

                    But it's obviously far from a full debugger.  You might check out the IDE solution elsewhere in this forum -- at least a few have got it to work.

                    BTW, at your website you are stating "The Debugging Toolkit for the Lightroom versions 3–6 SDK", but at the HTML page in the zip file is still stated "3–5 SDK".

                    Thanks, I'll fix that.

                    • 7. Re: How to get photo data outside processRenderedPhotos?
                      Griffel Level 1

                      I'm still dealing with this topic. The simple Lua Console Lightroom Plugin helped me, to prove my code sniplet to be valid:

                       

                      local activeCatalog = LrApplication.activeCatalog()
                      local listOfTargetPhotos = activeCatalog:getTargetPhotos()
                      local firstTargetPhoto = listOfTargetPhotos[1]
                      local fileName = firstTargetPhoto:getFormattedMetadata('fileName')

                       

                      The variable "fileName" shows the expected value. But when I insert the code sniplet in my plugin, the first three lines work, the last one not. So the question is: What causes this difference? My assumptions are:

                      1. The code sniplet depends on the calling context.
                      2. The first three lines can LR execute "directly".
                      3. To execute the last line (fetching the file specific information out of the catalog), LR opens a thread.

                      Do I need to use functions of the namespaces LrTasks or LrFunctionContext?

                      • 8. Re: How to get photo data outside processRenderedPhotos?
                        johnrellis Most Valuable Participant

                        If you execute those lines with a debugger, you'll see the following error message:

                        Untitled.png

                        That error message is LR's way of telling you that you need to call the method from within a task other than the main task of the plugin:

                        Untitled.png

                        Because so much of the SDK needs to be invoked from a task other than the main task, my plugins usually do all of their work within a task started by LrTasks.

                         

                        In general, when a plugin raises an error, LR will silently terminate that task and not display the error (which is what has been happening to you).  To get errors displayed, you need to wrap the body of each task in the following:

                        Untitled.png

                        My debugging toolkit has syntactic sugar that makes that easier, e.g.

                        Untitled.png

                        You also need to wrap callback functions that are passed to user-interface elements created by LrView.

                        • 9. Re: How to get photo data outside processRenderedPhotos?
                          Griffel Level 1

                          John, thanks a lot, you made my day!

                          It works and solved my issue.