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

A few questions about working with photos via the plugin script

Participant ,
Jul 11, 2020 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?

TOPICS
SDK , Windows

Views

430

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 3 Correct answers

LEGEND , Jul 11, 2020 Jul 11, 2020

"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.]

Votes

Translate

Translate
LEGEND , Jul 11, 2020 Jul 11, 2020

"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
...

Votes

Translate

Translate
LEGEND , Jul 11, 2020 Jul 11, 2020

"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.]

Votes

Translate

Translate
LEGEND ,
Jul 11, 2020 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.]

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

 

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
LEGEND ,
Jul 11, 2020 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.]

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
LEGEND ,
Jul 11, 2020 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.]

 

 

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

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
Participant ,
Jul 11, 2020 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((

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
LEGEND ,
Jul 11, 2020 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.]

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
LEGEND ,
Jul 11, 2020 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.]

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
Participant ,
Jul 12, 2020 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?

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
Participant ,
Jul 12, 2020 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!!!!

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
LEGEND ,
Jul 12, 2020 Jul 12, 2020

Copy link to clipboard

Copied

"And calling it outside of "catalog:with Write Access Do". And then it works!!!!"

 

Excellent.

 

Yeah, you have to be careful using withWriteAccessDo() -- it's not well-documented, and changes made inside it aren't often visible until you exit it.  As a general rule, I do as little as possible inside withWriteAccessDo().

 

[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
Participant ,
Jul 12, 2020 Jul 12, 2020

Copy link to clipboard

Copied

Good! Thank you so much for your help! And for the tips!

As a general rule, I do as little as possible inside withWriteAccessDo().

But it can't be used 2 times in a file? I when only understood, tried to put 2 of them in one file) That is, if something is very necessary, you need to do inside withWriteAccessDo().

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
LEGEND ,
Jul 12, 2020 Jul 12, 2020

Copy link to clipboard

Copied

"But it can't be used 2 times in a file?"

 

A number of my plugins call it many, many times.

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
Participant ,
Jul 12, 2020 Jul 12, 2020

Copy link to clipboard

Copied

I am using your debugger! This is an invaluable help! Thank you so much for it!

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
LEGEND ,
Jul 12, 2020 Jul 12, 2020

Copy link to clipboard

Copied

LATEST

I saw from your screenshots -- glad the debugger is useful.

 

[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