Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Lost extended information in custom fields - need to reinsert the data

Explorer ,
Jun 14, 2025 Jun 14, 2025

Long story, but I have lost about 5 years of extra information in custom fields, also backup. Luckely all this information is saved into a .json file with the images.
So for restoring them I was thinking to create a 'simple' lua script with a dialog for inserting this information back into lightroom.

 

My steps:

- Select the images where the information of the json file should be applied

- select the jason file

 

code not 100% correct but this should give  an idea of this will work

read the json file and put each value into a variable

ReturnContentFile = LrFileUtils.readFile(file) 
strTable = "{ " ..  ReturnContentFile .. " }"  
strTable = loadstring("return "..strTable)()
return strTable
-- must do the variable stuff
 
Put for each image the information into my custom fields
local catalog = LrApplication.activeCatalog()
for loop, photo in ipairs(photos) do
photo:readMetadata()
catalog:withPrivateWriteAccessDo(function(context)
photo:setPropertyForPlugin( _PLUGIN, 'MetaDataFile', "CFMetadata-"..CFMetadataFile)
photo:setPropertyForPlugin( _PLUGIN, 'AFFilmFormat', AFFilmFormat)
photo:setPropertyForPlugin( _PLUGIN, 'AFScanMethod', AFScanMethod)
photo:setPropertyForPlugin( _PLUGIN, 'AFScanEquipment', AFScanEquipment)
photo:setPropertyForPlugin( _PLUGIN, 'AFLightSource', AFLightSource)
photo:setPropertyForPlugin( _PLUGIN, 'AFDeveloppedAt', AFDeveloppedAt)
photo:setPropertyForPlugin( _PLUGIN, 'AFDevelopper', AFDevelopper)
photo:setPropertyForPlugin( _PLUGIN, 'AFDilution', AFDilution)
photo:setPropertyForPlugin( _PLUGIN, 'AFDevTime', AFDevTime)
photo:setPropertyForPlugin( _PLUGIN, 'AFDevNotes', AFDevNotes)
photo:setPropertyForPlugin( _PLUGIN, 'AFpushpull', AFpushpull)
photo:setPropertyForPlugin( _PLUGIN, 'AFFilmStock', StrFilmStock)
photo:setPropertyForPlugin( _PLUGIN, 'AFLightmeter', AFLightmeter)
photo:setPropertyForPlugin( _PLUGIN, 'ScanDevInfo', "ScanDevInfo-"..CFMetadataFile)
end ) 
end
 
Is this a good approach ?
TOPICS
macOS , SDK
180
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jun 14, 2025 Jun 14, 2025

That approach should work. But I recommend doing very thorough error checking at each method call, since things can go wrong with LR scripts very quickly, in mysterious ways.

 

Also, you might out Friedl's JSON Encode/Decode module for reading the JSON files. It's very robust and used by many plugins (including mine):

https://regex.info/blog/lua/json 

 

I just verified that the LR/Transporter plugin isn't able to import values into plugin custom metadata fields. It can export them but not import, unf

...
Translate
LEGEND ,
Jun 14, 2025 Jun 14, 2025

That approach should work. But I recommend doing very thorough error checking at each method call, since things can go wrong with LR scripts very quickly, in mysterious ways.

 

Also, you might out Friedl's JSON Encode/Decode module for reading the JSON files. It's very robust and used by many plugins (including mine):

https://regex.info/blog/lua/json 

 

I just verified that the LR/Transporter plugin isn't able to import values into plugin custom metadata fields. It can export them but not import, unfortunately. Otherwise, it might have been simpler to convert all the JSON files into a large CSV file to import.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 14, 2025 Jun 14, 2025

Thank you John,
As always usesefull feedback.

It's not possible to create one large CSV file as each json file contains information for that specific directory.
The data is about the analog film used digitalisation and development.

Thank you for pointing out the Friedl"s JSON module, i'll look into it for future use. For now i'm going to use my own method to read a json file. A matter of getting my data back in as quickly as possible.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 24, 2025 Jun 24, 2025

John,

Some feedback here, it works. I was able to put in about two years of data back in Lightroom, but yesterdag I found a problem.
Somewhere over the years I have change the naming of the fields of my json file, so I have two options rename everything in the plugin or do an adaption where I can use both values for feature use. But I don't know how to do this.
Short extract of my code with the use of Friedl's JSON lib

local waarde = JSON:decode(ReturnContentFile)
AFInsertFieldsFunctions.AFDoInsertExtraFields( waarde["AFFilmStock"], ..... )
Change to with both naming
AFInsertFieldsFunctions.AFDoInsertExtraFields( (waarde["AFFilmStock"] or waarde["nlpFilmFormat"]), ...  )


Thanks
Patrick

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 25, 2025 Jun 25, 2025

Hmm, I don't think I have enough information about the issue to provide useful feedback.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 25, 2025 Jun 25, 2025
LATEST

John,

I'm sorry, communication with email or through forums is sometimes difficult for me. As my wife sometimes tells me: I don't live in your head !

Meaning it stays in my head and I don't write this down, and I'm convinced that I have provided all the needed information.

 

As said above the naming of the fields in the json file have changed apparently over the years.
And I was looking for a way to make the plugin compatible with both naming conventions. From a previous conversation / help question you have provided a solution that contains an OR operator, and that did the trick.
So when I read the json file the value comes from (waarde["AFFilmStock"] or waarde["nlpFilmStock"]), and I do this for each field in the json file. 

I'll hope this makes sense.


But I got it working, what is the most important.

 

Again thank you

Patrick

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines