Highlighted

A few questions about working with photos via the plugin script

Participant ,
Jul 11, 2020

Copy link to clipboard

Copied

Hello everyone There are several questions that need to be asked. I really hope to get some answers here. Thank you in advance!

1. In the settings of LR installed - do not save the metadata automatically. Performed certain actions in the script to change the metadata. And an icon appeared next to the photos, clicking on which you can save them.
The question is, can it be done directly in the script without changing the global setting?

 

2. How can I correct the delay after importing a photo? If there is no delay, an error occurs when trying to change the metadata in it.
I came up with this method, is it correct? 

newLrPhoto  = catalog:addPhoto( newName .. '.arw')
while newLrPhoto == nil do
LrTasks.sleep(1)
end
InsertMetaData

Or is there a better option?

3. after creating a copy, the active selection is reset in the LR interface. In other words, no photos are highlighted. And the metadata panel is empty. How can I select a newly created photo in the code? in other words, emulate a mouse click on a new photo?

Most Valuable Participant
Correct answer by johnrellis | Most Valuable Participant

"I wrote several functions, now I want to put them in a separate file to use in another one. Is it possible to do this? And that is already more than 1000 lines(("

 

Check out flickr.lrdevplugin in the Sample Plugins folder of the SDK. It defines two modules, FlickrAPI and FlickUser. For example, FlickrAPI defines a number of public functions, e.g. FlickrAPI.showApiKeyDialog.

 

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

TOPICS
How to, SDK, Windows

Views

95

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

A few questions about working with photos via the plugin script

Participant ,
Jul 11, 2020

Copy link to clipboard

Copied

Hello everyone There are several questions that need to be asked. I really hope to get some answers here. Thank you in advance!

1. In the settings of LR installed - do not save the metadata automatically. Performed certain actions in the script to change the metadata. And an icon appeared next to the photos, clicking on which you can save them.
The question is, can it be done directly in the script without changing the global setting?

 

2. How can I correct the delay after importing a photo? If there is no delay, an error occurs when trying to change the metadata in it.
I came up with this method, is it correct? 

newLrPhoto  = catalog:addPhoto( newName .. '.arw')
while newLrPhoto == nil do
LrTasks.sleep(1)
end
InsertMetaData

Or is there a better option?

3. after creating a copy, the active selection is reset in the LR interface. In other words, no photos are highlighted. And the metadata panel is empty. How can I select a newly created photo in the code? in other words, emulate a mouse click on a new photo?

Most Valuable Participant
Correct answer by johnrellis | Most Valuable Participant

"I wrote several functions, now I want to put them in a separate file to use in another one. Is it possible to do this? And that is already more than 1000 lines(("

 

Check out flickr.lrdevplugin in the Sample Plugins folder of the SDK. It defines two modules, FlickrAPI and FlickUser. For example, FlickrAPI defines a number of public functions, e.g. FlickrAPI.showApiKeyDialog.

 

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

TOPICS
How to, SDK, Windows

Views

96

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
Jul 11, 2020 0
Most Valuable Participant ,
Jul 11, 2020

Copy link to clipboard

Copied

"Performed certain actions in the script to change the metadata. And an icon appeared next to the photos, clicking on which you can save them. The question is, can it be done directly in the script without changing the global setting?"

 

Use the undocumented photo:saveMetadata ().

 

[Use the blue 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
Reply
Loading...
Jul 11, 2020 1
Participant ,
Jul 11, 2020

Copy link to clipboard

Copied

Use the undocumented photo:saveMetadata (). - Unfortunately, this didn't help me...

Here is the part of the code where this should work. LR last.

				---Создание первой копии для обработки, при выделении нулевой, и фиксирование важных данных
				if process.action == 'create_edit' then
					if sp.fileType == 'NIL' and fpd.countChildPhotos == 1 then
						sp.label = 'O'
						local dp = {}
						InsertLabel(sp.photo, sp.label)
						InsertEditData(sp.photo, 'ORG', '')
						InsertVariation(sp.photo, sp.variation)
						dp.label = 'D'
						CreateCopy('"' .. sp.directory .. sp.fileName .. '"', '"' .. sp.partPath .. dp.label .. sp.maxVariation .. '.' .. sp.fileExt .. '"')
						CreateCopy('"' .. sp.directory .. sp.partFilename .. '.xmp"', '"' .. sp.partPath .. dp.label .. sp.maxVariation .. '.xmp"')
						dp.photo = catalog:addPhoto( sp.partPath .. dp.label .. sp.maxVariation .. '.arw')
						while dp.photo == nil do
							LrTasks.sleep(1)
						end
						InsertEditData(dp.photo, ostime .. ' начался процесс коррекции', '')
						InsertLabel(dp.photo, dp.label)
						sp.photo:saveMetadata()
						dp.photo:saveMetadata()
						catalog:setSelectedPhotos( sp.photo, dp.photo )
					end
				end

 The last command that works correctly is " Insert Label(dp. photo, dp. label)"
photo:save Metadata() and catalog:set Selected Photos( sp. photo, dp. photo ) they don't work anymore.
Here is an entry in GIF format

lr_dontsave.gif

 

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
Reply
Loading...
Jul 11, 2020 0
Most Valuable Participant ,
Jul 11, 2020

Copy link to clipboard

Copied

"How can I correct the delay after importing a photo?"

 

I haven't seen that, but it doesn't suprise me you are -- there are many undocumented places in the SDK where a plugin needs to wait for an operation to complete. If I'm confident the operation will complete in a second or two, then I just use a simple loop with a sleep interval of 0.05 -- it uses very little CPU time. But if the wait could potentially be longer, I do exponential backoff:

 

    local seconds = 0.0001
    while ...condition... do
        LrTasks.sleep (seconds)
        seconds = math.min (seconds * 2, 0.5)
        end

 

This minimizes the amount of time the plugin might need to wait while keeping the CPU time of the spin loop very small. 

 

[Use the blue 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
Reply
Loading...
Jul 11, 2020 1
Most Valuable Participant ,
Jul 11, 2020

Copy link to clipboard

Copied

"after creating a copy, the active selection is reset in the LR interface. In other words, no photos are highlighted. And the metadata panel is empty. How can I select a newly created photo in the code? in other words, emulate a mouse click on a new photo?"

 

Do you mean after creating a virtual copy?

 

In general, plugins can manipulate the selection with:

 

catalog:getTargetPhoto ()

catalog:getTargetPhotos ()

catalog:setSelectPhotos ()

The LrSelection module

 

These methods aren't well-designed, so you have to read their documentation and carefully and you might need a few lines of code.  (For example, catalog:setSelectPhotos() won't let you set the empty selection, so you have to test for that and use LrSelect.selectNone() in that special case.)

 

[Use the blue 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
Reply
Loading...
Jul 11, 2020 0
Participant ,
Jul 11, 2020

Copy link to clipboard

Copied

Do you mean after creating a virtual copy? - NO!

I refused to use virtual copies because they are not visible from another folder. So in the script, I duplicate the file that I process with a different name and import it to the directory. The main condition in my script is to select 1 file to duplicate. After importing the photo, the selection remains on the first file where the script was executed. I would like to move the selection to the newly created file. And I don't know how to do it.

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
Reply
Loading...
Jul 11, 2020 0
Participant ,
Jul 11, 2020

Copy link to clipboard

Copied

And 1 more question. I wrote several functions, now I want to put them in a separate file to use in another one. Is it possible to do this? And that is already more than 1000 lines((

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
Reply
Loading...
Jul 11, 2020 0
Most Valuable Participant ,
Jul 11, 2020

Copy link to clipboard

Copied

"I wrote several functions, now I want to put them in a separate file to use in another one. Is it possible to do this? And that is already more than 1000 lines(("

 

Check out flickr.lrdevplugin in the Sample Plugins folder of the SDK. It defines two modules, FlickrAPI and FlickUser. For example, FlickrAPI defines a number of public functions, e.g. FlickrAPI.showApiKeyDialog.

 

[Use the blue 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
Reply
Loading...
Jul 11, 2020 1
Most Valuable Participant ,
Jul 11, 2020

Copy link to clipboard

Copied

"The last command that works correctly is " Insert Label(dp. photo, dp. label)" photo:save Metadata() and catalog:set Selected Photos( sp. photo, dp. photo ) they don't work anymore."

 

It's not clear from your code fragment and screen recording what's going wrong. But saveMetadata() and setSelectedPhotos() definitely work. Here's a screen recording showing that:

https://www.dropbox.com/s/gs2c1b0i9s2gfbp/setselected-save.2020.07.11.mov?dl=0

 

[Use the blue 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
Reply
Loading...
Jul 11, 2020 1
Participant ,
Jul 12, 2020

Copy link to clipboard

Copied

I understand that it doesn't work for me because it doesn't have time. When working out the code and I put after inserting the data Debug. pause If Asked ("). THE debager window POPs up in LR, but the photo data has not been updated yet. This is noticeable by the color label. The original file turns yellow, and the created file turns green. In the code, the lines that change the label:
Insert Label(sp.photo, sp.label) and InsertLabel (dp.photo, dp.label).
That is, Debug.pause If Asked (") after Insert Label(dp.photo, dp.label) will work, but the photo will not change the label.
Shouldn't the next command wait for the previous one to run if it's running in a single environment?

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
Reply
Loading...
Jul 12, 2020 0
Participant ,
Jul 12, 2020

Copy link to clipboard

Copied

 

local xp = {}
local function saveMetadataOnChangedPhoto()
	---Дополнительный цикл действий по каждой из выделенных фото
	for i, changedPhoto in ipairs(xp.photo) do
		changedPhoto:saveMetadata()
		Debug.pauseIfAsked('if')
	end
end

 

YES! I did it! I wrote a function where I collect a list of photo objects that have changed. And calling it outside of "catalog:with Write Access Do". And then it works!!!!

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
Reply
Loading...
Jul 12, 2020 0