Skip to main content
Participant
October 10, 2017
Answered

applyDevelopSettings fails: ?:0: attempt to call up value '?' (a nil value)

  • October 10, 2017
  • 2 replies
  • 960 views

I am trying to write a first Lightroom plugin to automatically crop and rotate images.  I should be able to work out the crop settings (assuming I can translate to LR values later, and avoid limitations on setting crop values from the SDK), but I'm getting stuck at a more basic level applying any develop adjustment at all to any image.  Being new to LUA does not help

Whether I use something like photo:applyDevelopSettings({Exposure = 0.1}) or LrDevelopController.setValue("CropAngle", "0.1"), in both cases this fails with:

         ?:0: attempt to call up value '?' (a nil value)

Am I missing something in the way this call is formatted?  Or do I need a full set of settings from getDevelopSettings(), or a preset or something else?  In case it makes a difference, the target photos do not have any existing develop settings beyond import.

My full plugin that fails:

-- Access the Lightroom SDK namespaces.

local LrApplication       = import 'LrApplication'

local LrDevelopController = import 'LrDevelopController'

local LrTasks             = import 'LrTasks'

local LrDialogs           = import 'LrDialogs'

function MyPluginTopLevel()

  -- Main top level callback

  LrTasks.startAsyncTask(MyPluginTask, "MyPlugin main task")

end

function MyPluginTask()

  local catalog = LrApplication.activeCatalog()

  catalog:withWriteAccessDo("MyPlugin test", MyPluginApplyParams, {timeout = 10})

end

local function MyPluginApplyParams(context)

  local catalog        = LrApplication.activeCatalog()

  local selectedPhoto  = catalog:getTargetPhoto()

  if (selectedPhoto == nil) then

      LrDialogs.message( "Error: cannot get selected photo", nil, "info" );

      return nil

  else

     -- EITHER OF THESE TWO NEXT LINES FAILS:

     -- LrDevelopController.setValue("CropAngle", "0.1")

     selectedPhoto:applyDevelopSettings({CropAngle = "0.1"})

  end

end

-- Call top level:

MyPluginTopLevel()

This topic has been closed for replies.
Correct answer johnrellis

Also, when this line is executed:

catalog:withWriteAccessDo("MyPlugin test", MyPluginApplyParams, {timeout = 10})

MyPluginApplyParams hasn't been defined yet.  You can move the definition of that function up above where it's called.  Or if you prefer top-down definitions (as I do), you can use this idiom for declaring forward references:

local MyPluginApplyParams -- forward reference

function MyPluginTopLevel()

  -- Main top level callback

  LrTasks.startAsyncTask(MyPluginTask, "MyPlugin main task")

end

function MyPluginTask()

  local catalog = LrApplication.activeCatalog()

  catalog:withWriteAccessDo("MyPlugin test", MyPluginApplyParams) {timeout = 10})

end

function MyPluginApplyParams(context)

...

2 replies

johnrellis
johnrellisCorrect answer
Legend
October 10, 2017

Also, when this line is executed:

catalog:withWriteAccessDo("MyPlugin test", MyPluginApplyParams, {timeout = 10})

MyPluginApplyParams hasn't been defined yet.  You can move the definition of that function up above where it's called.  Or if you prefer top-down definitions (as I do), you can use this idiom for declaring forward references:

local MyPluginApplyParams -- forward reference

function MyPluginTopLevel()

  -- Main top level callback

  LrTasks.startAsyncTask(MyPluginTask, "MyPlugin main task")

end

function MyPluginTask()

  local catalog = LrApplication.activeCatalog()

  catalog:withWriteAccessDo("MyPlugin test", MyPluginApplyParams) {timeout = 10})

end

function MyPluginApplyParams(context)

...

johnrellis
Legend
October 10, 2017

Scratch my last reply -- I'm up way past my bedtime.  Because you used global variables for your functions, it doesn't matter which order you define them in. It's only if you define them as local variables that you need to declare the forward references.

HughMAuthor
Participant
October 10, 2017

John - thanks for the replies.  I had already tried using numbers for the parameters rather than "0.1", so this was not the issue.

Instead it was your second guess "local function" issue.  When I changed "local function MyPluginApplyParams(context)" to remove "local" it now works.  Thanks!

I will check out the debug toolkit later.

johnrellis
Legend
October 10, 2017

The value of CropAngle needs to be a number, e.g.

selectedPhoto:applyDevelopSettings({CropAngle = 10})

Also, you might consider using my Debugging Toolkit -- it will take about 45 mins to get up to speed using it, but it will save you a lot of grief down the road.