6 Replies Latest reply on May 19, 2011 1:11 AM by fovitan

    Custom import

    fovitan

      HI, I'm newbee in coding In Lightroom, and need to design a custom import to import photo automatic in Lightroom. I has coded a few code below using SDK 3.0. I would like to get help from your guys a fews things:

       

      1) It's the code below is the right way to begin?

      2) and I also got the error: the path is invalid, og miss when i calling catalog:addPhoto().

       

       

      I'm very thankfully for help from you guys.

       

      -- Lightroom API

      local catalog = import 'LrApplication'.activeCatalog()
      local
      path  = 'C:\\Users\\dev\\Desktop\\Test\\Picture\\camera.jpg'
      local
      LrFileUtils = import 'LrFileUtils'
      local
      LrPathUtils = import 'LrPathUtils'
      local
      LrTask =  import 'LrTasks'

       

       

      -- Add photo to catalog
      catalog:withWriteAccessDo("writeAccess", function(context)
              --syncablePhotos = catalog:getAllPhotos()
              local lrphoto = catalog.addPhoto(path)
      end)

       

      -- Code below is just for Test
      local LrDialogs = import 'LrDialogs'


      MyHWExportItem = {}
      function MyHWExportItem.showModalDialog()
          -- body of funtion
          --LrDialogs.message( "ExportMenuItem Selected", "Hello plugins!", "info" )
         
          if LrPathUtils.leafName(path) then
              local l = LrPathUtils.leafName( path)
              LrDialogs.message("ExportMenuItem Selected", l, "AtutoImportExport")
          else
              LrDialogs.message("ExportMenuItem Selected", "file not found ", "AtutoImportExport")
          end
      end



      MyHWExportItem.showModalDialog()

        • 1. Re: Custom import
          DawMatt Level 3

          Hi fovitan,

           

          Welcome!

           

          I think you'll need to change this line:

            local lrphoto = catalog.addPhoto(path)

          to

            local lrphoto = catalog:addPhoto(path)

           

          i.e. replace the period (.) with a colon (:).

           

          You are calling a method on an object here.  Your call was effectively passing a nil instead of the path hence the error complaining the file could not be found.

           

          The code looks OK but just be aware the SDK really isn't geared towards customising the import process so you may hit limitations as your usage gets more sophisticated. Please keep that in mind.

           

          Matt

          1 person found this helpful
          • 2. Re: Custom import
            fovitan Level 1

            Hi Matt, I'm so happy for your help, thanks a lot, and as you said, and the error is now gone, yeahh!!.   But a new error appear right after that, what is wrong?

             

            lr_error.PNG

             

            Here is my code so far:

             

            -- Lightroom API
            --local LrFolfder = import 'LrFolder' -- Creating an folder object

             

            local catalog = import 'LrApplication'.activeCatalog()
            local path  = 'C:\\Users\\dev\\Desktop\\Test\\Picture\\camera.jpg'
            local LrFileUtils = import 'LrFileUtils'
            local LrPathUtils = import 'LrPathUtils'
            local LrTasks =  import 'LrTasks'
            local LrDialogs = import 'LrDialogs'

             

            -- Export to a folder
                ---
            -- Code below is just for Test
                ---

             

            AddPhoto = {}
            function AddPhoto.showModalDialog()
                -- body of funtion
                --LrDialogs.message( "ExportMenuItem Selected", "Hello plugins!", "info" )
                -- logger:trace( "updateStatus() is executing." )
                LrTasks.startAsyncTask( function()
                    --Add photo to catalog
                        catalog:withWriteAccessDo("writeAccess", function(context)
                            --local syncablePhotos = catalog:getAllPhotos()
                            local lrphoto = catalog:addPhoto(path){}
                            --local folders = catalog:getFolders()
                    end)
                end)
               
                if LrPathUtils.leafName(path) then
                     local l = LrPathUtils.leafName( path)
                     LrDialogs.message("ExportMenuItem Selected", l, "AtutoImportExport")
                 else
                     LrDialogs.message("ExportMenuItem Selected", "file not found ", "AtutoImportExport")
                end
            end

             


            AddPhoto.showModalDialog()

            • 3. Re: Custom import
              DawMatt Level 3

              Hi,

               

              Haven't used that function before so I'm not exactly sure. I'm not sure what the {} at the end of the addPhoto line is there to achieve. Its possible that is the problem so try removing it, but it is possible that the file is not there or you don't have permissions. Why not work with a test file in c:\ until you get the details working?

               

              Matt

              • 4. Re: Custom import
                fovitan Level 1

                Hi again, the {} is removed, path = "c:\\camera.jpg" and the permission  is set to be read, write for everyone, but is still not working. Anyway thanks a lot for the help I've got from you.

                 

                Br,

                Tan

                • 6. Re: Custom import
                  fovitan Level 1

                  Hi, Thanks a lot for the link. I'll check it out.