Now I don't know how to actually read only the column entries of the txt file and displaying all the names appearing in it.
You can use LrFileUtils.readFile() to read the contents of a file into a string.
Another problem is that each photo has its own txt file in "nameofphoto.jpg.txt" So LR must know which txt file belongs to a photo.
photo:getRawMetadata ("path") will get you the full file path of a photo, which you can then use to find and open the corresponding .txt file.
So I started with the classic metadata definition:
Are you sure you want to create your own plugin-specific fields that can only be read by your plugin and LR? Consider instead using industry-standard metadata fields. E.g. the plugin could put the person names into a keyword and attach the keyword to the photo, or it could use the IPTC Extension field Person Shown (which might be better depends on the downstream use of the photos). The plugin can set the metadata fields using photo:setRawMetadata().
Thank you for the reply. Reading the file how I wanted worked fine and I chose to use keywords, as you suggested.
So now I tried to add the keywords to the pictures and I get:
"LrCatalog:withWriteAccessDo: could not execute action 'keywordProvider'. It was blocked by another write access call, and no timeout parameters were provided."
There's my function so far:
local catalog = LrApplication.activeCatalog()
local photos = catalog:getMultipleSelectedOrAllPhotos()
for i=1,#photos do
local photo = photos[i]
local photopath = photo:getRawMetadata("path")
local photoname = photo:getFormattedMetadata("fileName")
local folderpath = string.sub(photopath, 1, string.len(photopath) - string.len(photoname))
local metadataPath = folderpath .. "\.metaface\\" .. photoname .. ".txt"
local text = LrFileUtils.readFile(metadataPath)
local metadataValues = stringSplit(text)
for i = 0, #metadataValues do
catalog:withWriteAccessDo( "keywordProvider", function()
local keywords = catalog:createKeyword(metadataValues[i])
So what am I doing wrong?
That error message means another plugin is trying to access the catalog. Perhaps you had another instance of your plugin that you ran that was still running in background? Do you have other plugins installed that access the catalog in background?
The first thing to try is to add a timeout parameter of, say, 15 seconds.
Also, you'll find out soon enough that you need to pass a boolean parameter to catalog:createKeyword() to return an existing keyword if it already exists.
Thanx. It seems that there was a plugin which started automatically when I opened Lightroom. Now everything works fine
You'll probably want to add timeout parameters to catalog:withWriteAccessDo(), since a number of plugins run in the background.