Lightroom SDK: efficient way to obtain custom metadata for a plugin.

  • 1
  • Idea
  • Updated 8 years ago
catalog:batchGetRawMetadata( photos, { 'customMetadata' } ) is very inefficient, at least when large amounts of custom metadata are present. And, the return value is useful if one knows the target item name (and knows to prefix with plugin Id - presently not documented), but if handling en masse, not so much.

For example, it takes a long time to batch get custom metadata for a whole catalog, then isolate one plugin's metadata using code like:

--- Consolidate custom metadata for specified plugin into a lookup table (dictionary) form.
-- @param photo (LrPhoto, required) photo
-- @param pluginId (string, required) plugin id.
-- @param cMeta - (table, optional) batch of raw metadata including custom metadata for all plugins.
-- @return table - id/value members, or empty - never nil.
function CustomMetadata:getMetadata( photo, pluginId, cMeta )
local r = {}
if cMeta then
local t = cMeta[photo].customMetadata -- throw error if custom-metadata not included.
for k, v in pairs( t ) do
local p1, p2 = k:find( pluginId )
if p1 ~= nil then
if p1 == 1 then -- starts with
r[k:sub( p2 + 2 )] = v -- skip over plugin id and '.'
local s = photo:getRawMetadata( 'customMetadata' )
-- dbg( s )
for i, t in ipairs( s ) do
if t.sourcePlugin == pluginId then
r[] = t.value
return r

Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 389 Reply Likes

Posted 8 years ago

  • 1

Be the first to post a reply!