Skip to main content
Participating Frequently
July 17, 2015
Answered

Using getDevelopSettings()

  • July 17, 2015
  • 3 replies
  • 2180 views

Hello!

My name is Roman. I try to make a simple LR plug-in with following functions:

1. Plug-in must send commands via PC's COM port,

2. Plug-in must provide the list of presets to apply it to all photos in catalog,

3. Plug-in must provide the batch crop function.

Now I'm working with presets and something works fine (with kind help of johnrellis). For example, following code really changes all selected photos:

LrTasks.startAsyncTask(function() 

  catalog:withWriteAccessDo("PresetTry", function()

    local cat_photos = catalog.targetPhotos

    for i, photo in ipairs(cat_photos) do                 

      local preset = LrApplication.addDevelopPresetForPlugin( _PLUGIN, "TestPreset", { Shadows2012 = .4,  Exposure2012 = .3 })

      photo:applyDevelopPreset(preset, _PLUGIN)                   

    end

  end)

end)

But there are some problems:

1. When I try to get some information from loaded image some methods works, some don't.

For example, photo:getFormattedMetadata("fileSize") and photo:getFormattedMetadata("fileType") works fine, but

local settings = photo:getDevelopSettings()

LrDialogs.message( string.format("%d", settings["Exposure2012"]) )

returns 0. At the same time I see that Exposure is equal to 0.3 (after the previous code was executed) in the Develop tab.

Maybe, the original image wasn't changed with photo:applyDevelopPreset(preset, _PLUGIN), so original Exposure wasn't changed. 

2. I created some presets with names, for example, FirstPreset, SecondPreset etc. How can I apply it to images in my plug-in? I searched through the forum, but found nothing about it. 

3. I use the following code to get all photos in catalog:

local cat_photos = catalog.targetPhotos

for i, photo in ipairs(cat_photos) do                 

     _some_code_here_                

end

It works fine when I select all photos in catalog manually (when they all highlighted), but it doesn't when only one photo is selected - then I handle this and only this photo. What could be the problem?


Thank you in advance.

Best regards

Roman

This topic has been closed for replies.
Correct answer johnrellis

3. I use the following code to get all photos in catalog:

local cat_photos = catalog.targetPhotos

for i, photo in ipairs(cat_photos) do               

    _some_code_here_              

end

It works fine when I select all photos in catalog manually (when they all highlighted), but it doesn't when only one photo is selected - then I handle this and only this photo. What could be the problem?

I'm not sure exactly what you're observing here.  You're saying that when there is exactly one photo selected, catalog.targetPhotos is an array containing just one photo?  That is as it should be.  catalog.targetPhotos returns the same value as catalog:getTargetPhotos(), which the SDK defines as:

Retrieves the photo objects for the photos that would be affected by any photo-processing command. If there is a selection, this is the list of selected photos. Otherwise, it is the entire list of photos in the filmstrip.

What is the behavior that you want?

3 replies

Participating Frequently
July 20, 2015

Well, point 2 (using the presets) is now completely done. I take all plugins from

_system_disk_:\Users\_username_\AppData\Roaming\Adobe\Lightroom\Plugin Develop Presets\_plugin_name_\

let the user choose one to use, and undo changes if the result is not good.

Maybe it is better to use other path, but I didn't find the way to change catalog.

As I understand, point 3 (batch crop) is not available with SDK 5, which I use.

So now I focus at point 1 (COM port communication).

What did I do?

local ComPortName = "COM3"

serialin=io.open(ComPortName,"w") 

if serialin ~= nil then    

     LrDialogs.message( string.format("%s opened successfully", ComPortName) )

     serialin:write("A")

     serialin:close()

end

This code allows to send 'A' to COM3 if COM3 is available and the platform is Win.

But what to do if I don't know what port is available? How to get the list of available COM ports?

Maybe I can call some .exe file, that can return this list - and I can get it from plug-in?

Thank you in advance.

johnrellis
Legend
July 22, 2015

Maybe this will help: Windows command to quickly list the available COM ports on a system? | Off Topic | unofficial empeg BBS.  You can run a command line using LrTasks.execute().  You can capture the output by having the command line redirect to a temp file and then reading that temp file from within the plugin.

johnrellis
Legend
July 17, 2015
2. I created some presets with names, for example, FirstPreset, SecondPreset etc. How can I apply it to images in my plug-in? I searched through the forum, but found nothing about it.

If you want to retrieve a plugin's preset by its name, you'll have to iterate through the results of LrApplication.getDevelopPresetsForPlugin() looking for a preset where preset:getName() is the one you want.

johnrellis
johnrellisCorrect answer
Legend
July 17, 2015

3. I use the following code to get all photos in catalog:

local cat_photos = catalog.targetPhotos

for i, photo in ipairs(cat_photos) do               

    _some_code_here_              

end

It works fine when I select all photos in catalog manually (when they all highlighted), but it doesn't when only one photo is selected - then I handle this and only this photo. What could be the problem?

I'm not sure exactly what you're observing here.  You're saying that when there is exactly one photo selected, catalog.targetPhotos is an array containing just one photo?  That is as it should be.  catalog.targetPhotos returns the same value as catalog:getTargetPhotos(), which the SDK defines as:

Retrieves the photo objects for the photos that would be affected by any photo-processing command. If there is a selection, this is the list of selected photos. Otherwise, it is the entire list of photos in the filmstrip.

What is the behavior that you want?

Participating Frequently
July 17, 2015

What is the behavior that you want?

For the test purposes I used Export function in the Lightroom and added 10 photos to my workspace. I thought, this is my catalog, so I'll get all 10 with catalog.targetPhotos even if only 1 of them currently selected.

johnrellis
Legend
July 17, 2015

I'll provide feedback on your points 1-3 above later today, but I just noticed your requirement 3, "Plug-in must provide the batch crop function.".  Unfortunately, develop presets can't apply crop settings: Lightroom SDK: Please assure *all* develop settings and metadata are available in Lr4. So at least with the documented SDK API, there is no way a plugin can apply cropping.


However, you might investigate photo:applyDevelopSettings(), an undocumented method that was introduced in LR 6/CC 2015. It may be able to apply crop settings.  Alternatively, you might be able to use the LrDevelopController. See this thread for more information: Lightroom 6 SDK Changes.

johnrellis
Legend
July 17, 2015

1. When I try to get some information from loaded image some methods works, some don't.

For example, photo:getFormattedMetadata("fileSize") and photo:getFormattedMetadata("fileType") works fine, but

local settings = photo:getDevelopSettings()

LrDialogs.message( string.format("%d", settings["Exposure2012"]) )

returns 0. At the same time I see that Exposure is equal to 0.3 (after the previous code was executed) in the Develop tab.

Do the following completely outside of the call to catalog:withWriteAccessDo():

LrTasks.sleep (30); ...photo:getDevelopSettings ()...

I know years ago there were reports that changing the develop settings didn't immediately "take", though I've never seen that.  Exiting withWriteAccessDo() and then waiting for 30 seconds could test that.

Also, you might looking into using Debug.pause() in the debugger toolkit as an easier way of setting "breakpoints" and examining data values.