Copy link to clipboard
Copied
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()
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")
en
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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)
...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I just confirmed with testing that CropAngle requires a number, silently ignoring string values.
Perhaps what happened in your testing is that through repeated loads of different versions of your file, you got inconsistent versions of the functions, adding to the confusion. It's one reason to use local functions rather than global.