Skip to main content
Inspiring
March 8, 2024
Question

Add metadata after moving file

  • March 8, 2024
  • 1 reply
  • 179 views

I don't know of this is possible, I need to rename a lot of images and then add metadata to them.

short code

LrFileUtils.copy(SourceFile, TargetFile)
		--------- Add to catalog --------
		local result = catalog:withWriteAccessDo("Reimport photos", function(context)	
			RenamedFile = catalog:addPhoto(TargetFile)	
		end)
		
		for _, newphoto in ipairs(RenamedFile) do
		  catalog:withPrivateWriteAccessDo(function(context)
		  	newphoto:setPropertyForPlugin( _PLUGIN, 'xxx', yyy)
		  end)	  
		end

There is no metadata added to the new image.

 

 

This topic has been closed for replies.

1 reply

johnrellis
Legend
March 10, 2024

In a plugin I wrote several years ago, I found that the LrPhoto returned by catalog:addPhoto() wasn't usable. I had to call catalog:findPhotoByPath() to retreive the new LrPhoto. Here's the code fragment:

 

        --[[ Import the image and then get access to it with 
        findPhotoByPath(). We can't use the results of addPhoto() 
        because applyDevelopSettings() acts wonky with it. ]]
    Util.withWriteAccessDo ("Import image", function () 
        catalog:addPhoto (path)
        end)
    local photo = catalog:findPhotoByPath (maskPath)

 

Most likely a bug, but I couldn't narrow it down and it wasn't worth my time to report it.

Inspiring
March 10, 2024

John,

Indeed, that's why I had installed your debug plugin. Could not understand why.

For now as my structure has a unique name I have used find by name  solution. Works fine for me.