-
1. Re: collections becomes visible after 5 - 10 seconds. Message until it appears.
johnrellis Apr 10, 2012 11:42 AM (in response to dhmc05)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()?
-
2. Re: collections becomes visible after 5 - 10 seconds. Message until it appears.
areohbee Apr 10, 2012 2:36 PM (in response to dhmc05)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.
-
3. Re: collections becomes visible after 5 - 10 seconds. Message until it appears.
dhmc05 Apr 27, 2012 7:11 AM (in response to dhmc05)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()
-
4. Re: collections becomes visible after 5 - 10 seconds. Message until it appears.
johnrellis Apr 27, 2012 11:49 AM (in response to dhmc05)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.
-
5. Re: collections becomes visible after 5 - 10 seconds. Message until it appears.
dhmc05 May 3, 2012 9:56 AM (in response to johnrellis)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.
-
6. Re: collections becomes visible after 5 - 10 seconds. Message until it appears.
johnrellis May 3, 2012 10:26 AM (in response to dhmc05)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.
-
7. Re: collections becomes visible after 5 - 10 seconds. Message until it appears.
dhmc05 May 5, 2012 7:21 AM (in response to johnrellis)@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.
-
8. Re: collections becomes visible after 5 - 10 seconds. Message until it appears.
johnrellis May 7, 2012 9:12 AM (in response to dhmc05)I may have time to look at it later this week. You can see my email address here.
-
9. Re: collections becomes visible after 5 - 10 seconds. Message until it appears.
dhmc05 May 10, 2012 9:20 AM (in response to johnrellis)Thank!!
I send it to the e-mail address.
-
10. Re: collections becomes visible after 5 - 10 seconds. Message until it appears.
johnrellis May 12, 2012 10:03 PM (in response to dhmc05)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).
-
11. Re: collections becomes visible after 5 - 10 seconds. Message until it appears.
dhmc05 May 14, 2012 10:38 AM (in response to johnrellis)I want to thank John for his excelent advice. Thank you!