• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

problems with adding photos to a collection immediately after emptying that collection

Engaged ,
Jun 02, 2020 Jun 02, 2020

Copy link to clipboard

Copied

Is there a problem with the code below? it works fine if the collection doesn't already exist but if it already exists I see only one or two photos in the collection even though the count by the collection in LR's collection list is the number of photos that are in the list of photos i'm adding

 

		sortedCollection = catalog:createCollection( "0.BFEP UnSortable", nil, true )

		sortedCollection:removeAllPhotos( )
		sortedCollection:addPhotos( UnSortable )
TOPICS
SDK

Views

523

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 02, 2020 Jun 02, 2020

Copy link to clipboard

Copied

My experience with catalog:withWriteAccessDo() is that it is "wierd" -- sometimes the changes made to catalog objects are visible immediately, sometimes the changes are not visible until the code has exited writeWriteAccessDo().  I can never remember the details of what's allowed. The documentation sometimes hints at this, e.g. the SDK doc for createCollection() says:

 

"The new collection is not available for access until that function returns."

 

What does that really mean?  I don't know, since I've got some code that does createCollection() followed by removeAllPhotos() and addPhotos(), all in the same writeWriteAccessDo(), and it works both when the collection exists and when it doesn't.

 

You might try using two calls to writeWriteAccessDo(), the first to create the collection or return the existing, the second to remove the photos and add the new ones.  My code that creates and deletes potentially very large collection does this so it can wrap the removal of photos in a progress bar -- LR has a severe O(n^2) performance bug where it can take a minute or more to remove all the photos from a collection with thousands of photos.

 

If none of this helps, make a stripped down self-contained file (a dozen or so lines at most) that you can run as a stand-alone script from the Scripts menu showing the problem and post it here.

 

[Use the blue reply button under the first post to ensure replies sort properly.]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 02, 2020 Jun 02, 2020

Copy link to clipboard

Copied

LATEST

thanks, John. Giving everything its own withWriteAccessDo seems to have done the job.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines