8 Replies Latest reply on Feb 5, 2016 7:32 AM by mr_fluffy

    I need to add some data to a photo

    mr_fluffy

      I think that create a companion XML file with datas and open It with a plugin action to show data is the best way, but If someone import photo to a catalog moving them to catalogs folder, XML remain in original folder. Also, if someone rename a photo, I can't access anymore the photoname.xml. How to resolve this? I only want to have always a companion data's file with my photo, even if people import and move to a catalog photos or rename them.

        • 1. Re: I need to add some data to a photo
          johnrellis Most Valuable Participant

          Instead of a companion .xml file, you could store your data in industry-standard XMP in a custom schema.   The XMP for JPEG, TIFFs, DNGs, PNGs, and videos is stored inside the file, and the XMP for raw files is stored in a sidecar .xmp file.  Storing the data in XMP ensures that it will stay with the file if you rename, move, or import photos inside LR.

           

          Your plugin could invoke the free Exiftool to read and write the metadata. Before writing the metadata to the file, your plugin could invoke the undocumented photo:saveMetadata()  to do the equivalent of Metadata > Save Metadata To File.

           

          I think it will take a couple hours to figure out how to configure Exiftool to read and write custom XMP schemas, but it looks pretty well documented.

          • 2. Re: I need to add some data to a photo
            mr_fluffy Level 1

            Your're right, we have tried to implement them with XMP but we have some problem. There is some possibilities to write down data inside Lightroom database, associate them with a photo file and then read them from the database?

            • 3. Re: I need to add some data to a photo
              johnrellis Most Valuable Participant
              There is some possibilities to write down data inside Lightroom database, associate them with a photo file and then read them from the database?

              Yes, plugins can create custom metadata fields for photos in the database.  See Chapter 4: Working With Metadata in the LR SDK Guide.

               

              Custom metadata can be very useful, but it doesn't meet all your requirements.  If you add custom metadata to a photo and then import that photo into a new catalog, the custom metadata won't transfer (because it is stored in the catalog, not the photo's file).

              • 4. Re: I need to add some data to a photo
                mr_fluffy Level 1

                I want to continue with the road of Lightroom's custom metadata. If user want to keep metadata, they have to backup the LR's catalog.

                In chapter 4, I've not understand why I can't fill metadata's values  with my values. How to set properly a custom metadata's field proprerly from the plugin?

                • 5. Re: I need to add some data to a photo
                  johnrellis Most Valuable Participant

                  If you've defined a custom metadata field as described in chapter 4, then your plugin can use photo:getPropertyForPlugin() and photo:setPropertyForPlugin(). 

                  • 6. Re: I need to add some data to a photo
                    mr_fluffy Level 1

                    Thank you so much! no I try.

                    • 7. Re: I need to add some data to a photo
                      mr_fluffy Level 1
                      for TOMAREOMO in LrFileUtils.files(filePath) do
                      if LrPathUtils.extension( TOMAREOMO ):lower() == "xml" then
                      LrDialogs.message(filePath .. " " .. TOMAREOMO .. " " .. masterDir)
                      local result, err = LrFileUtils.copy(TOMAREOMO, masterDir)
                      LrDialogs.message(tostring(result))
                      end
                      end

                       

                      error is null.

                      result is false, It doesn't copy my file.

                      file:

                      /Users/myname/Documents/photos/test/DSC_0440.NEF.XML


                      directory where I want to copy:

                       

                      Users/myname/Pictures/LightroomMasters/


                      if I open file and directory with terminal, I can do it. Why It fails?

                      • 8. Re: I need to add some data to a photo
                        mr_fluffy Level 1

                        I'll answer to myself as a note for the others: when you use LrFileUtils.copy(filePath, destinationDir), on the destinationDir you have to concat the name of the file, not only the destination folder.

                        For example, if you have to copy on User/myname/pics the file test.jpg, destinationDir is User/myname/pics/test.jpg