Lightroom SDK: publishService:getCollectionByLocalIdentifier

  • 2
  • Idea
  • Updated 7 years ago
From a collection handling point of view, the catalog and publish services can be treated as collection sets - they both have the same methods for collection management. This is real nice, except:

publish services lack the method to get a collection by local ID.

Plug this one little hole and collection handling plugins (which include handling for publish service collections as well as reglar) become much smoother...

Reminder: "We" also need a method to *get* the search description for a smart collection (the complement of setSearchDescription).

Workaround:

--- Call to assure fresh data before looking up collections based on id.
--
function PublishServices:computeCollLookup()
self.collLookup = {}
local fromColl, fromColls, fromSets, fromSet
function fromColl( coll )
--Debug.logn( str:fmt( "lookup for coll '^1', ID: ^2", coll:getName(), coll.localIdentifier ) )
self.collLookup[coll.localIdentifier] = coll
end
function fromColls( colls )
for i, v in ipairs( colls ) do
fromColl( v )
end
end
function fromSets( sets )
--Debug.logn( str:fmt( "lookup for ^1 sets", #sets ) )
for i, v in ipairs( sets ) do
if v:type() == 'LrPublishedCollection' then
fromColl( v )
elseif v:type() == 'LrPublishedCollectionSet' then
fromSet( v )
else
app:error( "what?" )
end
end
end
function fromSet( set )
--Debug.logn( str:fmt( "lookup for set", set:getName() ) )
local collSets = set:getChildCollectionSets()
local colls = set:getChildCollections()
fromColls( colls )
fromSets( collSets )
end
local srvs = catalog:getPublishServices() -- get publish services for all plugins.
--Debug.logn( str:fmt( "lookup for ^1 services", #srvs ) )
for i, v in ipairs( srvs ) do
fromSet( v ) -- treat pub-srv as coll-set (cheating a little...).
end
end

function PublishServices:getCollectionByLocalIdentifier( id )
if self.collLookup == nil then
self:computeCollLookup()
end
return self.collLookup[id]
end


Thanks,
Rob
Photo of Rob Cole

Rob Cole

  • 4831 Posts
  • 385 Reply Likes

Posted 7 years ago

  • 2

Be the first to post a reply!