1 2 Previous Next 50 Replies Latest reply on Jul 1, 2012 7:46 PM by areohbee

    Using a plugin across multiple Catalogues

    John Spacey Level 1

      Hi peeps

       

      Using a plugin across multiple Catalogues

       

      Given LR shuts down and restarts to load anotehr catalogue, can  this be done?   What I specifically want to do is select a bunch of photos in one catalague, and then a get a plugin to load up another catalogue and select photos with the same name in a specified folder in this catalogue.

       

      Cheers in advance

        • 1. Re: Using a plugin across multiple Catalogues
          areohbee Level 5

          Prefs persist between catalogs, so do your bookeeping in prefs (or other disk file if you prefer).

           

          Then you need to run a script to kill Lightroom, and restart with new catalog. The first part of this is the hardest.

           

          This python command works on Windows, but I dunno how to do it on Mac:

           


          os.system( 'taskkill /IM lightroom.exe /T' )

           

          Matt Dawson may chime in, since he wrote a restart script.

           

          Another option until something better comes along, is to get set up, then prompt the user to quit Lightroom.

          • 2. Re: Using a plugin across multiple Catalogues
            John Spacey Level 1

            Thanks for the speedy reply Rob

             

            So I guess at least we're talking about writing a list of those selected photos to a prefs file, or any old txt file ( can that be done? ). restarting lightroom manually and running a plugin script to read from the file.

             

            It would be cool to automate from start to finish, but I don't mind manually restarting

            • 3. Re: Using a plugin across multiple Catalogues
              areohbee Level 5

              Right. Although Lr prefs was not intended as a scratch-pad for this type of thing, it will work just fine, and keep you from having to deal with another file, and keep the user from seeing it and wondering about it... - any form of persistent storage will work... - you can clear prefs after they've done their job, to be tidy, but also you could delete a temp file that you used...

               

              Everything can be done via plugin, except killing Lightroom, which can also be done by plugin, but only in conjunction with a non-plugin app, or script, or shell command..., and of course that script will also need to restart Lightroom, since your plugin will no longer be running...

               

              If you go the external text file route, consider using serialized lua for the text file format. This is what native Lightroom does for presets and prefs and such... you can kype the code from John Ellis Debug.lognpp (in toolkit), or see LuaText.lua module in framework/data subdir of any of my newer plugins.

               

              R

              • 4. Re: Using a plugin across multiple Catalogues
                John Spacey Level 1

                Just been thinking .......

                 

                if I save a table of selected photos in prefs in an original catalogue, then when I open the new catalogue the IDs of those photos won't be recognised by the new catalogue. Correct?

                • 5. Re: Using a plugin across multiple Catalogues
                  areohbee Level 5

                  I think you'll have to find photos by path, not ID.

                  • 6. Re: Using a plugin across multiple Catalogues
                    John Spacey Level 1

                    Yup that's what I thought.   I need to modify part of the path anyway is I want to select the original versions rather than the exported versions.  I did some experiementation on saving to prefs last night in a test plug so getting to grips with that side of things.

                    • 7. Re: Using a plugin across multiple Catalogues
                      DawMatt Level 3

                      Hi,

                      Rob Cole wrote:

                       

                      Prefs persist between catalogs, so do your bookeeping in prefs (or other disk file if you prefer).

                       

                      Then you need to run a script to kill Lightroom, and restart with new catalog. The first part of this is the hardest.

                       

                      This python command works on Windows, but I dunno how to do it on Mac:

                       


                      os.system( 'taskkill /IM lightroom.exe /T' )

                       

                      Matt Dawson may chime in, since he wrote a restart script.

                       

                      Another option until something better comes along, is to get set up, then prompt the user to quit Lightroom.

                      I think in this instance I'd tend towards saving this information to a text file rather than the Lightroom prefs. Why? You can't guarantee the prefs will be persisted to disk instantly and it's possible you could try to kill Lightroom before it has finished writing the info. At best you would pointlessly restart Lightroom (as the selection information was yet to be stored). At worst you might cause the prefs to become corrupted, and possibly the catalog itself if Lightroom is killed mid-write. Using a separate text file just seems more prudent.

                       

                      The technique I used in the script only works in a script (not a plugin), and only supports restarting the current catalog. Doesn't fit the problem space.

                       

                      If you are working only on Windows there is a neat alternative I stumbled across a while back. I'm pretty sure it worked in a plugin when I tried it. If you use something like Process Explorer to examine the command line for Lightroom after you have used the "open catalog" option in the File menu, it looks something like this:

                           lightroom.exe -restart "full_path_to_catalog.lrcat"

                      So if you run a command like this it starts a new instance of Lightroom, and the new instance tells the old instance to shutdown. Neat and much safer. Unfortunately I tried it on the Mac and they use a different argument/catalog identifier (not file path) I couldn't decipher to indicate the new catalog to be opened. I had been planning to use this technique to turn my script into a plugin but the platform specific nature of the trick made this a non-starter for me. Maybe this platform restriction isn't a problem for you.

                       

                      Matt

                      • 8. Re: Using a plugin across multiple Catalogues
                        John Spacey Level 1

                        Matt Dawson wrote:

                         

                        ......

                         

                        At worst you might cause the prefs to become corrupted, and possibly the catalog itself if Lightroom is killed mid-write. Using a separate text file just seems more prudent.

                         

                        .....

                         

                        Matt

                         

                        Hi Matt, thanks for replying

                         

                        Reading between the lines of the above it implies the plugin prefs are stored in the catalogue?   Is that actually the case? I was wondering where the prefs were stored, but I did notice during my recent test plugin escapade where I'm experiementing storing prefs, that the prefs were recalled across any catlaogue opened.

                         

                        I am indeed only on Windows, but any Mc info is of course useful of others reading this thread

                         

                        I think i'll try storing the selected photo list both in the prefs and as a text file It'll be a good learning exercise

                        • 9. Re: Using a plugin across multiple Catalogues
                          areohbee Level 5

                          Prefs are not stored in the catalog, they're stored in a file which you can inspect using a text editor (serialized lua format). (look in Lightroom "app-data" folder, findable using Lightroom preferences dialog box, or LrPathUtils.getStandardFilePath).

                           

                          What Matt was saying, is that prefs are written first to ram, then later, in a leisurely fashion, they are written to disk.

                           

                          What you don't want to do is yank the rug from Lightroom's feet while it's writing those prefs to disk.

                           

                          I'm inclined to agree with him in this case - better to use an independent text file, so your plugin can assure completed writing before the restart (if you are willing to commit to user initiated restarting, then these issues do not exist).

                           

                          I expect if you use Lightroom.exe -restart command, it will terminate gracefully. But, nothing graceful about taskkill, and safer/defensive programming is generally good practice.

                           

                          Rob

                          • 10. Re: Using a plugin across multiple Catalogues
                            John Spacey Level 1

                            Hmmmm,had a look in the lightroom folder in AppData but can't find a prefs file

                            • 11. Re: Using a plugin across multiple Catalogues
                              areohbee Level 5

                              On windows 7, it's

                               

                              C:\Users\{username}\AppData\Roaming\Adobe\Lightroom\Preferences\Lightroom 4 Preferences.agprefs

                              • 12. Re: Using a plugin across multiple Catalogues
                                John Spacey Level 1

                                Doh! - yes found that earlier but couldn't find the entry the first time. Got it now - cheers

                                 



                                • 13. Re: Using a plugin across multiple Catalogues
                                  John Spacey Level 1

                                  Interesting.    I've added two lua routines to my test plugin

                                   

                                  1] selection = catalog:getTargetPhotos()   and saves the table 'selection' in prefs using prefs.selection = selection .  Also displays number of selected pics and lists their filenames

                                   

                                  2] reads prefs and displays number of selected pics and lists their filenames

                                   

                                  All this works until I close and open with another catalogue. if I do that the number of selected photos stored in prefs is corr3ectly read, but fails on   photo:getFormattedMetadata('fileName') in ....

                                   

                                  for i, photo in ipairs (prefs.selection) do

                                              display_string_selected = display_string_selected .. i .. "] " .. photo:getFormattedMetadata('fileName') .. " \n"

                                          end

                                   

                                   

                                  I checked the prefs file in Appdata and found the reason why.... it appears the table is written withthe correct amount of entries ( 3 photos were selected ) but is empty.

                                   

                                  selection = {\

                                          {\

                                          },\

                                          {\

                                          },\

                                          {\

                                          },\

                                   

                                   

                                  Hmmmmmmmmm?

                                  • 14. Re: Using a plugin across multiple Catalogues
                                    areohbee Level 5

                                    Although there is an api for storing tables in prefs, I had a bad experience doing it one time (I corrupted the prefs during development, and table access time was greater than storing elements individually), and haven't retried since.

                                     

                                    Instead, I use pseudo table storage, like:

                                     

                                    local prefs = LrPrefs.prefsForPlugin()

                                    for i, photo in ipairs( photos ) do

                                     

                                         local key = "photo_path_" .. i

                                         prefs[key] = photo:getRawMetadata( 'path' )

                                     

                                    end

                                     

                                    You may be able to get by with:

                                     

                                    local selects = {}

                                    for i, photo in ipairs( photos ) do

                                     

                                         selects[#selects + 1] = photo:getRawMetadata( 'path' )

                                     

                                    end

                                    prefs.selection = selects

                                     

                                    But I don't do this anymore because of aforementioned bad experience.

                                     

                                    Explanation: Use Debug.lognpp to dump 'selection' and you'll see there is "tons" of stuff, with looping references etc. - you leave it up to Lightroom to figure which elements to store - in your case: none were stored. Realize prefs are for storing strings and numbers..., not objects.

                                     

                                    ?

                                    R

                                    • 15. Re: Using a plugin across multiple Catalogues
                                      John Spacey Level 1

                                      Cheers Rob,

                                       

                                      just before coming back here I just tried creating a table full of strings of the selected filenames with

                                       

                                           selection = catalog:getTargetPhotos()

                                           photofileNameTable = {}

                                              for i, photo in ipairs (selection) do

                                                  photofileNameTable[i] = photo:getFormattedMetadata('fileName')      

                                              end

                                         

                                           prefs.photofileNameTable = photofileNameTable

                                       

                                       

                                      and it worked fine.  To be honest I didn't really want to store the whole photo object anyway as there's tons of redundant data adn the prefs file would be huge if the selected photos numbered into the thousands.

                                       

                                      Talking of using prefs to store numbers, I stored a number, and found it was stored as a string as I needed to use tonumber() upon retrieving it. No biggie.

                                       

                                      Getting there

                                      • 16. Re: Using a plugin across multiple Catalogues
                                        areohbee Level 5

                                        John Spacey wrote:

                                         

                                        Talking of using prefs to store numbers, I stored a number, and found it was stored as a string as I needed to use tonumber() upon retrieving it.

                                         

                                        This sounded wrong, so I double-checked. My evaluation: number in => number out; e.g. code:

                                         


                                        prefs["asdf"] = 2

                                        local v = prefs["asdf"]

                                        app:show{ info="^1: ^2", v, type( v ) }

                                        prefs["asdf"] = nil

                                         

                                        app "shows" 2: number

                                         

                                        R

                                        • 17. Re: Using a plugin across multiple Catalogues
                                          John Spacey Level 1

                                          maybe the code I had was storing the nunber I entered into a editable feild as a string. I'll look into it laters. Currently working on mainplug code to select pics in another catalogue as per thread

                                          • 18. Re: Using a plugin across multiple Catalogues
                                            areohbee Level 5

                                            edit-fields are strings, unless you set min, max, precision - then it's interpreted as a number.

                                            • 19. Re: Using a plugin across multiple Catalogues
                                              areohbee Level 5

                                              Matt Dawson wrote:

                                               

                                              lightroom.exe -restart "full_path_to_catalog.lrcat"

                                               

                                              Matt,

                                               

                                              On Mac: open "full_path_to_catalog.lrcat" is equivalent.

                                               

                                              This info courtesy of John Ellis - we thank you.

                                               

                                              Rob

                                              • 20. Re: Using a plugin across multiple Catalogues
                                                areohbee Level 5

                                                John,

                                                 

                                                My experience: prefs are not persisted to disk until a graceful exit of Lightroom (user initiated, not plugin initiated). Thus, you *must* use an independent text file for persistent storage if you are planning to auto-restart Lightroom. Unless you figure something out that I've missed...

                                                 

                                                Rob

                                                • 21. Re: Using a plugin across multiple Catalogues
                                                  DawMatt Level 3

                                                  Rob Cole wrote:

                                                   

                                                  On Mac: open "full_path_to_catalog.lrcat" is equivalent.

                                                   

                                                  That's odd. On Windows you can use that same approach to open the desired catalog from the command line, but not to launch a second instance of Lightroom and have it convince the first instance to shutdown in an orderly fashion. If this works as stated then why would they use a more convoluted mechanism to swap active catalogs when a simple mechanism like this was available?

                                                   

                                                  Matt

                                                  • 22. Re: Using a plugin across multiple Catalogues
                                                    johnrellis Most Valuable Participant

                                                    why would they use a more convoluted mechanism to swap active catalogs when a simple mechanism like this was available?

                                                    Perhaps someone knowledgable about the Mac application architecture can step in and correct my surmises from just a tiny bit of reading:

                                                     

                                                    The Mac application libraries have their own mechanisms (built on the underlying Unix framework) for launching applications, opening documents, and managing their windows on the desktop. There is some mechanism other than Unix command-line arguments for passing verbs like "open" and their parameters to applications.  When you run "ps" and you see a Lightroom process with the arguments that look like "-psn_0_4233212", that command-line argument is simply the Mac process serial number assigned by the framework.  I'm guessing that when the application starts, it takes the process serial number from the Unix command line and identifies itself to the Mac process manager, which bootstraps the communication of the application with the rest of the framework.

                                                     

                                                    The "open" command is also layered on top of the framework -- it's a command-line utility that invokes the same framework function that the Finder uses to open a document.  That is, the "open" command itself is not a fundamental building block in the framework.  Presumably, Lightroom invokes the same framework libraries internally to identify itself as a Mac application, to respond to open-document requests, and to relaunch itself.

                                                     

                                                     

                                                    • 23. Re: Using a plugin across multiple Catalogues
                                                      John Spacey Level 1

                                                      Rob Cole wrote:

                                                       

                                                      John,

                                                       

                                                      My experience: prefs are not persisted to disk until a graceful exit of Lightroom (user initiated, not plugin initiated). Thus, you *must* use an independent text file for persistent storage if you are planning to auto-restart Lightroom. Unless you figure something out that I've missed...

                                                       

                                                      Rob

                                                       

                                                      "prefs are not persisted to disk until a graceful exit of Lightroom (user initiated"

                                                       

                                                      I'd haver to recheck to be 100% on this, but I'm sure I've seen the updated prefs written ( lookign in the prefs file ) when the plugin routine has finished. But yup on a huige selection this could indeed take some time.

                                                      • 24. Re: Using a plugin across multiple Catalogues
                                                        John Spacey Level 1

                                                        UPDATE ON PLUGIN PROGRESS:

                                                         

                                                        Some very interesting discussion going on in this thread.

                                                         

                                                        I've got another query which has cropped up .....

                                                         

                                                        I keep my exported photos in a seperate catalogue to the originals. The reason for this plugin was to select photos in the Exports Catalogue and have the original photos they were exported from selected in the originals Catalogue. two

                                                         

                                                        I run two identical path structures, e.g

                                                         

                                                        E:\Exports\2012\2012-05-23 Photoshoot\2012-05-23_142562_Photoshoot.jpg

                                                        E:\Originals\2012\2012-05-23 Photoshoot\2012-05-23_142562_Photoshoot.DNG

                                                         

                                                         

                                                        I export all my photos to jpgs, but the originals can be either DNG, PEF(pentax RAW), jpg or TIF

                                                         

                                                        I've now succesfully got a routine to search the originals catalogue by replacing Exports with Originals in the path and trying with DNG, PEF, jpg or TIF file extensions.

                                                         

                                                        ..... however I then realised that many photos were exported from virtual Lightroom copies and of course don't have an original on disk.

                                                         

                                                        So the query is how would I locate these in the originals catalogue? Hmmmmm

                                                        • 25. Re: Using a plugin across multiple Catalogues
                                                          areohbee Level 5

                                                          John Spacey wrote:

                                                           

                                                          I'd haver to recheck to be 100% on this, but I'm sure I've seen the updated prefs written ( lookign in the prefs file ) when the plugin routine has finished. But yup on a huige selection this could indeed take some time.

                                                           

                                                          I didn't do exhaustive checking, but I did check that if the restart occurred via same task that wrote prefs, after sleeping for 10 seconds, they were not there upon restart. Maybe operator error though - will be interested in what you find.

                                                           

                                                          R

                                                          • 26. Re: Using a plugin across multiple Catalogues
                                                            areohbee Level 5

                                                            So the query is how would I locate these in the originals catalogue? Hmmmmm

                                                             

                                                            Consider writing an export filter which stores the (catalog and) photo ID of the source photo as metadata in the exported photo. That way it works regardless of source extension, or copy type, or filename case (find-by-path is case sensitive, despite file-system being not case sensitive!), or even if the source file has been renamed, or moved...

                                                            • 27. Re: Using a plugin across multiple Catalogues
                                                              John Spacey Level 1

                                                              Rob Cole wrote:

                                                               


                                                              So the query is how would I locate these in the originals catalogue? Hmmmmm

                                                               

                                                              Consider writing an export filter which stores the (catalog and) photo ID of the source photo as metadata in the exported photo. That way it works regardless of source extension, or copy type, or filename case (find-by-path is case sensitive, despite file-system being not case sensitive!), or even if the source file has been renamed, or moved...

                                                               

                                                              Excellent idea for future exports!! ( actually I'm suprised LR doesn't do this anyway )  And yup I think I'll definitely be writing such a routine!!

                                                               

                                                              I don't fancy re-exporting all 180,000 photos in the collection though - So I do need to find a way of locating those virtual copies

                                                               

                                                               

                                                               

                                                              ETA: yes I noticed searching for filename extensions was case sensitive. Code takes care ofthat annoyingly

                                                              • 28. Re: Using a plugin across multiple Catalogues
                                                                areohbee Level 5

                                                                Consider a maintenance run that retrofits existing exports with the new info (so no re-rendering is required).

                                                                 

                                                                Or maybe use a mapping file instead, so you don't need to touch exported photos (just export all 180,000 but don't render, instead compute source ref info and store in mapping file).

                                                                 

                                                                You could even widdle that mapping file down as future exports migrate info to exported file's metadata.

                                                                 

                                                                If you already have a solution for real copies, perhaps it would be simplest to just have a virtual copy lookup file.

                                                                 

                                                                ?

                                                                • 29. Re: Using a plugin across multiple Catalogues
                                                                  John Spacey Level 1

                                                                  Some interesting ideas there

                                                                   

                                                                  btw - just rechecked and it seems that

                                                                   

                                                                  catalog:findPhotoByPath( "photo.jpg" ) will also find

                                                                   

                                                                  photo.JPG

                                                                  • 30. Re: Using a plugin across multiple Catalogues
                                                                    areohbee Level 5

                                                                    John Spacey wrote:

                                                                     

                                                                    catalog:findPhotoByPath( "photo.jpg" ) will also find

                                                                     

                                                                    photo.JPG

                                                                     

                                                                    Sounds like it's been (silently) fixed.

                                                                     

                                                                    R

                                                                    • 31. Re: Using a plugin across multiple Catalogues
                                                                      John Spacey Level 1

                                                                      Getting somwhere with teh problem of finding virtual copies from an export.

                                                                       

                                                                      1] Virtual copies get assigned a name in the Copy Name metadata feild. "Copy 1", "Copy 2", "Copy 3", etc  

                                                                       

                                                                      now as long as all copies including original get exported at the same time then exports are named

                                                                       

                                                                      photo.jpg

                                                                      photo-2.jpg [copy 1]

                                                                      photo-3.jpg [copy 2]

                                                                       

                                                                      2] As, for example, photo-2.jpg only has a virtual original ion the caralogue contining the originals, the next step is to develop the search routing to look for "-x" at the end of the filename and then search the originals catalogue for photos having that filename and "Copy (x-1)" in the Copy Name feild.

                                                                       

                                                                      3] It's worth noting when exporting virtual copies that if you only export "photo.dng ( Copy 1 )" then the export will be named photo.dng and not photo-2.dng. I'm always careful to always export all versions of the same photo at once.

                                                                      • 32. Re: Using a plugin across multiple Catalogues
                                                                        areohbee Level 5

                                                                        Sounds a little dicey, but if it works it works...

                                                                        • 33. Re: Using a plugin across multiple Catalogues
                                                                          John Spacey Level 1

                                                                          Rob Cole wrote:

                                                                           

                                                                          Sounds a little dicey, but if it works it works...

                                                                           

                                                                          Yup fairly dicey I would say.  Pending proper testing I have got somethign working    Found an interseting issue though. I'm using

                                                                           

                                                                          catalog:setSelectedPhotos( activePhoto, otherSelectedPhotos )

                                                                           

                                                                          to do the actual selection, but I've found that any photos in 'activePhoto' of 'otherSelectedPhotos' are only selected if their source is active.  Therefore the workaroudn is to make sure catalog/All Photographs is selected as the source before ruinnign the routine

                                                                          • 34. Re: Using a plugin across multiple Catalogues
                                                                            areohbee Level 5

                                                                            Yep. I have a photo selection routine that assures sources are selected too - kindofa pain... Another thing is the lib filter: can't select 'em if they're being filtered out (or are buried in stack).

                                                                            • 35. Re: Using a plugin across multiple Catalogues
                                                                              John Spacey Level 1

                                                                              I guess as I'm searching for the pics I could compile a table of their parents and then activate those sources before selecting the found pics.

                                                                              • 36. Re: Using a plugin across multiple Catalogues
                                                                                areohbee Level 5

                                                                                John Spacey wrote:

                                                                                 

                                                                                I guess as I'm searching for the pics I could compile a table of their parents and then activate those sources before selecting the found pics.

                                                                                You got it.

                                                                                 

                                                                                Also, after setting selection, verify selection. If all photos you want selected are not selected (despite setting their sources active), then you may need to:

                                                                                 

                                                                                * clear lib filter

                                                                                * wait a moment

                                                                                 

                                                                                Note: bottom feeders in stack are not selectable (unless you also assure stacks are expanded, which requires keystroke injection).

                                                                                 

                                                                                R

                                                                                • 37. Re: Using a plugin across multiple Catalogues
                                                                                  John Spacey Level 1

                                                                                  Rob Cole wrote:

                                                                                   

                                                                                  John Spacey wrote:

                                                                                   

                                                                                  I guess as I'm searching for the pics I could compile a table of their parents and then activate those sources before selecting the found pics.

                                                                                   

                                                                                  Note: bottom feeders in stack are not selectable (unless you also assure stacks are expanded, which requires keystroke injection).

                                                                                   

                                                                                  R

                                                                                   

                                                                                  You've lost me with that. Although I know waht a stack is in genral terms

                                                                                  • 38. Re: Using a plugin across multiple Catalogues
                                                                                    areohbee Level 5

                                                                                    If you have two photos in a collapsed stack, and you try to select the one underneath, you can't (it won't become "selected" ).

                                                                                     

                                                                                    ?

                                                                                    • 39. Re: Using a plugin across multiple Catalogues
                                                                                      John Spacey Level 1

                                                                                      Ahh you mean a stack of pics rather than a programming stack - gotcha!

                                                                                      1 2 Previous Next