Copy link to clipboard
Copied
Hi,
I have a plug-in that creates serveral collections and adds photos to a 1000 - 2000 photos to these.
Also in the loop the message is shown of the progress. After the loop has finished the processing is also finished.
This all works fine.
The code is something like:
After the loop has finished and the created collectiona are populated the collections becomes visible after 5 to 10 seconds. There is a delay. On slower systems this can be longer.
The problem is that the user sees and thinks that nothing happens and tries again.
What I want is to show a message which automatically disappears when the collections gets visible. No pushing buttons, only the message that he should we for the collection to become visible.
Other solutions are also welcome.
A little example would help alot.
| xxxxCollection = catalog:createCollection( ... ) |
| for i, photo in ipairs(cat_photos) do |
| message = 'processed: ' .. i | ||||
| progressScope:setCaption(message) | ||||
| .. processing |
| -- adding photo to collection. | |||||
| xxxxCollection:addPhotos{ photo } | |||||
| progressScope:setPortionComplete( i, nCountSelected ) | |||||
| end | |||||
| progressScope:done() | |||||
| end) | |||||
| end) | |||||
| end |
Copy link to clipboard
Copied
In general, the LR user interface updates asynchronously from changes made to the catalog, and changes made by plugins can take a while to get reflected in the user interface. But one thought about your situation:
Is the progressScope:done() inside or outside of the call to catalog:withWriteAccessDo()? That is, is your structure:
catalog:withWriteAccessDo()
catalog:createCollection()
loop
collection:addPhoto()
progressScope:setPortionComplete()
progressScope:done()
If the call to progressScope:done() is inside the call to catalog:withWriteAccessDo(), then perhaps it is indicating that the operation is finished before all the changes to the catalog actually get committed. What happens if you move progressScope:done() outside of the call to catalog:withWriteAccessDo()?
Copy link to clipboard
Copied
Just to help reinforce one of the points John is making - collections aren't created until after you exit the with-write-access-do function. Likewise, nothing else is really done database-wise until the database transaction is complete - after returning from with...do.
It's worth noting that last edit date will not be the time the change was initiated, but the time it was finally committed.
Copy link to clipboard
Copied
I understand the reason, but how can i show the user that although nothing happens on screen Lightroom is processing the Collections.
I have tried with one parent progressScope which should emcompass all the functions and a child progressScope which should show the iteration over the individual photos.
This is my code, but only the first time the parent progress bar is shown. I'm doing something wrong.
My code is below. I have been trying for hours, but cannot get it right.
Could anyone correct it so that I get 2 bars, the other goes from 1 - 4 and the inner from 1 - photo count.
So that after the collections async have been created the other bar should finish.
local LrTasks = import 'LrTasks'
local catalog = import "LrApplication".activeCatalog()
local LrFunctionContext = import 'LrFunctionContext'
local LrProgressScope = import 'LrProgressScope'
local LrDialogs = import 'LrDialogs'
local myLogger = import 'LrLogger'( 'AddImages' )
-- myLogger:enable( "logfile" )
local message
local messageTitle
local messageOk
local messageCancel
function AddImagesToCollection()
-- This should be the MAIN progressScope (progressScopeLarge) : this should encompass all
-- Phase 1: Removing the Collection hierarchy
-- Phase 2: Initializing
-- Phase 3: Iterating all the photos
-- Child progressScope - should show the progress of the individual photos. (progressScope)
-- Phase 4: Building the Collection tree.
-- After that all the images have been edited
-- The problem is that the user is seeing nothing for some time. Thats why I want to show the progress of the main scope.
local progressScopeLarge = LrProgressScope {
title = 'My plug-in processing ...',
functionContext = context,
}
LrTasks.startAsyncTask(function()
message = "Remove previous CollectionSet"
progressScopeLarge:setCaption(message)
progressScopeLarge:setPortionComplete( 1, 4 )
catalog:withWriteAccessDo( "Remove previous CollectionSet", function()
local collectionSet = catalog:createCollectionSet( "My plug-in Collection", nil, true )
collectionSet:delete()
end)
message = "Initializing ..."
progressScopeLarge:setCaption(message)
progressScopeLarge:setPortionComplete( 2, 4 )
local cat_photos = catalog.targetPhotos
local nCountSelected = #cat_photos
progressScope = LrProgressScope {
title = 'My plug-in: adding images ...',
functionContext = context,
}
catalog:withWriteAccessDo( "Create new CollectionSet", function()
message = "Iterating all photos"
progressScopeLarge:setCaption(message)
progressScopeLarge:setPortionComplete( 3, 4 )
-- loop through each of the photos
for i, photo in ipairs(cat_photos) do
message = 'processed: ' .. i
progressScope:setCaption(message)
<< All the processing per image >>
progressScope:setPortionComplete( i, nCountSelected )
end
progressScope:done()
end)
end)
message = "Building Collection tree"
progressScopeLarge:setCaption(message)
progressScopeLarge:setPortionComplete( 4, 4 )
progressScopeLarge:done()
end
AddImagesToCollection()
Copy link to clipboard
Copied
Re the progressScopes, it's not obvious what might be going wrong.
But it's not clear from your code fragment whether you've addressed the underlying issue, which is you'd prefer the collections and photos to appear in the user interface immediately when they're added. Your code fragment appears to imply that the collection set and collections are all being created within one single catalog:withWriteAccessDo().
I suggest that you restructure your code to create each collection set/collection and add each photo to a collection within separate calls to catalog:withWriteAccessDo:
catalog:withWriteAccessDo
delete collection set
create collection set
for each photo
...
catalog:withWriteAccessDo
create collection
...
catalog:withWriteAccessDo
add photo to collection
Then it's more likely that the changes made to collections and their contents will appear incrementally on the screen as the plugin executes.
Copy link to clipboard
Copied
Hi,
I understand that it is normal behaviour that after the loop the collections are created / made visible and that this takes some time. This is no problem for me.
It is not neccesary to have the collections been build and visible during the loop. Also I think this would use a lot of performance.
For me it is enough to show "child progressbar" increase in the loop.
The only thing I want is to give the user a sign of life between the moment the last photo is added to the last collection (the end of the loop) and the moment the collections appear visible on screen for the user.
Copy link to clipboard
Copied
Right. But if you can't get the progress scope to work incrementally, another way to show "signs of life" is to have the collection building appear incrementally as it occurs, as sketched out above. Personally, I would prefer that, since that's the way LR itself works with all of its long-running operations.
If performance of incremental collection-building becomes an actual problem (it may not be), then you can avoid that problem by processing the photos in batches of, say 5 at a time. The Any Filter plugin, which searches entire catalogs of tens of thousands of photos, uses that simple approach to show incremental results without sacrificing performance.
Copy link to clipboard
Copied
@John R. Ellis,
Would you be willing to have a look at the plug-in?
The plug-in is very straight forward.
Ofcourse, you could have a copy for free.
Copy link to clipboard
Copied
I may have time to look at it later this week. You can see my email address here.
Copy link to clipboard
Copied
Thank!!
I send it to the e-mail address.
Copy link to clipboard
Copied
To close this thread: The plugin's code had a number of undeclared variables, some of which were causing the progressScope to not get properly created. By default, Lua errors are not displayed, so these were slipping past the author silently. I recommended that he use the Debugging Toolkit or Rob Cole's plugin framework (which incorporates the toolkit).
Copy link to clipboard
Copied
I want to thank John for his excelent advice. Thank you!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now