How to remove photo from catalog programmatically

New Here ,
Dec 20, 2019 Dec 20, 2019

Copy link to clipboard

Copied

Hello,

I am able to add a photo by using catalog:addPhoto( path, stackWithPhoto, position )

 

I'd like to remove the photo once my operation is done. Or I'd like to completely remove the LrFolder from the Catalog. 

 

Is there any way to do this? I didn't find a way in the SDK. 

 

Any feedback would be greatly appreciated.

Thanks in advance!

TOPICS
SDK

Views

477

Likes

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

correct answers 1 Correct answer

LEGEND , Dec 21, 2019 Dec 21, 2019

Unfortunately, the SDK doesn't provide methods for removing photos or folders.  I've always guessed that this was deliberate -- Adobe wanted to protect users from poorly written plugins.

 

As a klutzy workaround, one of my plugins takes this approach: When it's finished with an imported photo, it deletes the underlying file from disk and moves the LrPhoto into a special collection called "OK To Delete".  Then the user can periodically delete that collection.

 

It's very unlikely at this point la

...

Likes

Translate

Translate
LEGEND ,
Dec 21, 2019 Dec 21, 2019

Copy link to clipboard

Copied

Unfortunately, the SDK doesn't provide methods for removing photos or folders.  I've always guessed that this was deliberate -- Adobe wanted to protect users from poorly written plugins.

 

As a klutzy workaround, one of my plugins takes this approach: When it's finished with an imported photo, it deletes the underlying file from disk and moves the LrPhoto into a special collection called "OK To Delete".  Then the user can periodically delete that collection.

 

It's very unlikely at this point late in LR Classic's life that Adobe would ever add a delete method to LrPhoto.

 

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

Likes

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
New Here ,
Dec 23, 2019 Dec 23, 2019

Copy link to clipboard

Copied

@johnrellis thank you so much for your answer. IMO, SDK, at least, should allow removing photos which have been added by catalog:addPhoto but before this, there are lots of things to fix 

Likes

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
New Here ,
Dec 16, 2021 Dec 16, 2021

Copy link to clipboard

Copied

@grcn you can delete files from the catelogue as well as from the directory folder. 

1) For remove selected files from the actiev catalogue, use photo:addOrRemoveFromTargetCollection() function. 

Below is the example to delete the files from the active catalogue.

 

local LrApplication = import "LrApplication"
local catalog = LrApplication.activeCatalog()
local photos = catalog:getTargetPhotos()
for p, photo in ipairs(photos ) do
    photo:addOrRemoveFromTargetCollection()
end

 

2) Remove files from the targeted directory folder. 

 

LrFileUtils.delete( path )Immediately deletes the file or directory at a given path. If the path refers to a directory, all of the contents are deleted. Use with care; in most cases, moveToTrash() is preferred.

First supported in version 1.3 of the Lightroom SDK.

Parameters

1. path (string) The path.

Return value

(Boolean) True on success. On failure, can return a second parameter indicating the reason.

 

 

Here is the example how you can delete folder from the targeted path.

 

local LrFileUtils = import("LrFileUtils")
local exportPath = LrPathUtils.child(_PLUGIN.path, "Exported Photos")
local filePath = assert(exportPath .. "\\folderName\\")
LrFileUtils.delete(filePath)

 

I thing this will help a lot.

Thank you!

Likes

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 ,
Dec 17, 2021 Dec 17, 2021

Copy link to clipboard

Copied

LATEST

"For remove selected files from the active catalogue, use photo: addOrRemoveFromTargetCollection() function."

 

Unfortunately, that just adds or removes the photo from the target collection, not from the catalog itself.

Likes

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