I'm experiencing an issue since the LR version 11.0 update where the SDK commands concerning collections are not taking effect on the application view. For example, if I'm trying to run the following code:
localLrTasks = import'LrTasks'
localLrApplication = import'LrApplication'
LrTasks.startAsyncTask( function ()
localcatalog = LrApplication.activeCatalog()
localmessage = catalog:withWriteAccessDo("Managing collections", function ()
The collections in App view may sometime not be updated. Sometime it is only partially updated (not all images appear in the collection). I know from the output in the code that the commands were executed successfully. Moreover, if I'm restarting LR, the collections are indeed updated.
*I'm running on macOS and, as I understand, this issue does not occur on Windows.
Are you familiar with the issue? Is there anything else I should add to the code?
How many photos are being added to the collections? When I run that script on a 1000-photo catalog, it completes nearly instantaneously, and the created collections appear fully populated. But when I run it ona catalog with 36K photos, it takes many minutes to complete, and the collections didn't appear in the Collections panel until a couple minutes after starting the script.
collection:addPhotos() has long had an n-squared performance bug that's causing this misbehavior:
So try re-running your test, and use Activity Monitor to observe the CPU time of the Lightroom Classic process while running the script. After the CPU utilization drops to a few percent, do the collections now appear in the Collections panel fully populated?
Glad you found a workaround. Reviewing the code in some of my plugins, I see that I've done the same thing, but I had written comments saying that trying to add photos to a newly created collection inside a singlewithWriteAccessDo() would fail with an error (the collection wouldn't appear to be created until the withWriteAccessDo() exited). But not all my plugins split up creation and adding. So this, and the n-squared performance bug, is clearly something fragile in LR internals that interacts badly with refreshing the UI.