Lightroom SDK: LrDevelopController.setValue() doesn't work with Enable* settings

  • 2
  • Problem
  • Updated 3 months ago
  • (Edited)
LrDevelopController.setValue() doesn't set the Enable* settings controlling the toggle switches of the Develop panels (e.g. EnableDetail), even though .getValue() retrieves the values correctly. A workaround is to use photo:applyDevelopSettings().

Tested on LR 7.4 / Macos 10.13.5.

The test script below demonstrates the problem. Running it produces this output:



--[[----------------------------------------------------------------------------
12345678901234567890123456789012345678901234567890123456789012345678901234567890
Tests the Enable* settings with photo:applyDevelopSettings(), 
LrDevelopController.getValue() and .setValue().
------------------------------------------------------------------------------]]
local showErrors
if false then 
    require "Require".path ("../common")
    require "strict"
    local Debug = require "Debug".init ()
    showErrors = Debug.showErrors
else
    showErrors = function (x) return x end
    end
local LrApplication = import "LrApplication"
local LrDevelopController = import "LrDevelopController"
local LrDialogs = import "LrDialogs"
local LrTasks = import "LrTasks"
local catalog = LrApplication.activeCatalog ()
local getValue = LrDevelopController.getValue
local photo = catalog:getTargetPhoto ()
local setValue = LrDevelopController.setValue
local enableKeys = { "EnableCalibration",
    "EnableCircularGradientBasedCorrections", "EnableColorAdjustments",
    "EnableDetail", "EnableEffects", "EnableGradientBasedCorrections",
    "EnableGrayscaleMix", "EnableLensCorrections",
    "EnablePaintBasedCorrections", "EnableRedEye", "EnableRetouch",
    "EnableSplitToning", "EnableTransform"}
LrTasks.startAsyncTask (showErrors (function () 
    local applyFails, getFails, setFails = "", "", ""
    for _, enableKey in ipairs (enableKeys) do
        local value = photo:getDevelopSettings ()[enableKey]
        catalog:withWriteAccessDo ("test", showErrors (function ()
            photo:applyDevelopSettings {[enableKey] = not value}
            end))
        if photo:getDevelopSettings ()[enableKey] ~= not value then
            applyFails = applyFails .. " " .. enableKey
            end
        local value = photo:getDevelopSettings ()[enableKey]
        if getValue (enableKey) ~= photo:getDevelopSettings ()[enableKey] then
            getFails = getFails .. " " .. enableKey
            end
        setValue (enableKey, not value)         
        if photo:getDevelopSettings ()[enableKey] ~= not value then
            setFails = setFails .. " " .. enableKey
            end
        end
    LrDialogs.message ("Testing Results", 
        "photo:applyDevelopSettings() fails on: " .. applyFails .. "\n\n" ..
        "LrDevelopController.getValue() fails on: " .. getFails .. "\n\n" ..
        "LrDevelopController.setValue() fails on: " .. setFails)
    end))
Photo of John R. Ellis

John R. Ellis, Champion

  • 3696 Posts
  • 967 Reply Likes

Posted 3 months ago

  • 2
Photo of ragrawal

ragrawal, Employee

  • 23 Posts
  • 4 Reply Likes
Hi John,

I ran your script and i am also getting the same error dialog as you.

Although, I also see that the script actually works since there are corresponding entry in the History table and UI also gets updated. Can you please confirm the same.

Is it that the changes are actually getting applied successfully, but when you retrieve it again for comparing it is returning the old value ? (and hence the dialog error)

-ragrawal
Photo of John R. Ellis

John R. Ellis, Champion

  • 3696 Posts
  • 967 Reply Likes
Thanks for looking into this.   You're seeing the toggles in the UI change and the history entries due to the call to photo:applyDevelopSettings(). Here's a simpler script that tries and fails to toggle the value of EnableDetail using LrDevelopController:

--[[----------------------------------------------------------------------------
12345678901234567890123456789012345678901234567890123456789012345678901234567890
Tries to toggle the value of EnableDetail using LrDevelopController.
------------------------------------------------------------------------------]]
local LrApplication = import "LrApplication"
local LrDevelopController = import "LrDevelopController"
local LrDialogs = import "LrDialogs"
local catalog = LrApplication.activeCatalog ()
local getValue = LrDevelopController.getValue
local photo = catalog:getTargetPhoto ()
local setValue = LrDevelopController.setValue
local before = getValue ("EnableDetail")
setValue ("EnableDetail", not before)
local after = getValue ("EnableDetail")
LrDialogs.message ("Results", 
    "Before: " .. tostring (before) .. "\nAfter: " .. tostring (after))

When I run it, the toggle in the UI doesn't change, there's no history entry, and the script shows:

Photo of ragrawal

ragrawal, Employee

  • 23 Posts
  • 4 Reply Likes
Hi John,

I went through the setValue/getValue code. Seems the setValue doesn't support the case when the value is not a number and hence can't be used to enable/disable the panels.
We are looking into this. Thanks for reporting.

-ragrawal
Photo of John R. Ellis

John R. Ellis, Champion

  • 3696 Posts
  • 967 Reply Likes
Thanks for the update.