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

Using getDevelopSettings()

New Here ,
Jul 17, 2015 Jul 17, 2015

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

TOPICS
SDK
2.2K
Translate
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 , Jul 17, 2015 Jul 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

...
Translate
LEGEND ,
Jul 17, 2015 Jul 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.

Translate
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 17, 2015 Jul 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. 

Translate
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 ,
Jul 17, 2015 Jul 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.

See catalog:getTargetPhoto(), :getTargetPhotos(), and :getMultipleSelectedOrAllPhotos().

I'll try to find out tomorrow. Thank you again!

Translate
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
Explorer ,
Aug 14, 2015 Aug 14, 2015
LATEST

johnrellis wrote:

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.

great idea, with the param names taken from an sidecar xmp you can set the crop with an plugin using LrDevelopController.setValue( param, value )

numbers are relative, so you have to look at the aspect ratio for different files

e.g.:

CropTop="0"

CropLeft="0.204416"

CropBottom="1"

CropRight="0.795584"

CropAngle="6.75401"

CropConstrainToWarp="1"

and no, a preset does not accept this params 😞

Translate
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 17, 2015 Jul 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.

Translate
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 17, 2015 Jul 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?

Translate
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 ,
Jul 17, 2015 Jul 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.

Translate
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 17, 2015 Jul 17, 2015
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.

See catalog:getTargetPhoto(), :getTargetPhotos(), and :getMultipleSelectedOrAllPhotos().

Translate
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 ,
Jul 17, 2015 Jul 17, 2015

, hello and thank you very much for your help.

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.

As I understand, presets for current plug-in lives here:

...\Lightroom\Plugin Develop Presets\_name_of_plug-in_\

I put some my presets to this folder. I successfully read all of their names with

local presets = LrApplication.getDevelopPresetsForPlugin(_PLUGIN)

for i, preset in ipairs(presets) do

     LrDialogs.message( preset:getName() )

end

but I failed to apply them like this:                   

local presets = LrApplication.getDevelopPresetsForPlugin(_PLUGIN)

for i, preset in ipairs(presets) do

     if preset:getName() == "TestPreset2" then

          LrDialogs.message( "GOTCHA" )

          photo:applyDevelopPreset(preset, _PLUGIN)      

     end

end

i got GOTCHA message and that's all.

TestPreset2 in Develop tab changes photo, so I can see the difference.

Translate
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 17, 2015 Jul 17, 2015

local presets = LrApplication.getDevelopPresetsForPlugin(_PLUGIN)

for i, preset in ipairs(presets) do

     if preset:getName() == "TestPreset2" then

          LrDialogs.message( "GOTCHA" )

          photo:applyDevelopPreset(preset, _PLUGIN)     

     end

end

Is this executed inside a catalog:withWriteAccessDo()?

Translate
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 ,
Jul 17, 2015 Jul 17, 2015

Yes, the full code is

LrTasks.startAsyncTask(function() 

    catalog:withWriteAccessDo("PresetTry", function()

                   

        local cat_photos = catalog.targetPhotos

        local presets = LrApplication.getDevelopPresetsForPlugin(_PLUGIN)         

        for i, photo in ipairs(cat_photos) do                                            

            for j, preset in ipairs(presets) do

                if preset:getName() == "TestPreset2" then

                    LrDialogs.message( "GOTCHA" )

                    photo:applyDevelopPreset(preset, _PLUGIN)      

                end

            end                      

        end

    end)

end)

Translate
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 17, 2015 Jul 17, 2015

I don't see anything obviously wrong, unfortunately.

Translate
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 ,
Jul 17, 2015 Jul 17, 2015

I don't see anything obviously wrong, unfortunately.

I found that if I call preset that I created from plug-in with LrApplication.addDevelopPresetForPlugin() all works fine, but if I call preset that I created in Develop tab nothing happens.

Well, let's check the difference.

The preset created from plugin had following contents:

s = {

    id = "8D6A011D-C83E-4D08-9F92-09DD5536F4C6",

    internalName = "TestPreset",

    title = "TestPreset",

    type = "Develop",

    value = {

        Contrast2012 = -70,

        Exposure2012 = 0.3,

    },

    version = 0,

}

The preset created from Develop tab:

s = {

    id = "3A8783C7-200D-473D-9C47-15709CCCF6F8",

    internalName = "MyNewPreset",

    title = "MyNewPreset",

    type = "Develop",

    value = {

        settings = {

            AutoLateralCA = 0,

            Blacks2012 = 0,

_much_bla_bla_bla_

            SplitToningShadowSaturation = 0,

            ToneCurveName2012 = "Linear",

            ToneCurvePV2012 = {

                0,

                0,

                255,

                255,

            },

            ToneCurvePV2012Blue = {

                0,

                0,

                255,

                255,

            },

            ToneCurvePV2012Green = {

                0,

                0,

                255,

                255,

            },

            ToneCurvePV2012Red = {

                0,

                0,

                255,

                255,

            },

            Vibrance = 0,

            VignetteAmount = 0,

            VignetteMidpoint = 50,

            WhiteBalance = "Custom",

            Whites2012 = 0,

            orientation = "AB",

        },

        uuid = "F366933A-00B4-409A-A287-5B2C29AEE1E6",

    },

    version = 0,

}

Well, there is some 'settings' section.

I deleted

'settings = {'

and corresponding

'},'

(just before 'uuid = "F366933A-00B4-409A-A287-5B2C29AEE1E6",')

and now preset works fine!

, thank you very much!

Translate
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 17, 2015 Jul 17, 2015

Yes, presets created by LrApplication.addDevelopPresetForPlugin() have a different representation than presets created from the Develop module.  You can't move a preset's .lrtemplate file from the folder "Plugin Develop Presets" to the folder "Develop Presets" or vice versa.

Translate
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 ,
Jul 20, 2015 Jul 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.

Translate
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 21, 2015 Jul 21, 2015

Maybe this will help: Windows command to quickly list the available COM ports on a system? | Off Topic | unofficial empeg ....  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.

Translate
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