Copy link to clipboard
Copied
My goal was to create a script that resets BOTH Crop and Transform.
First of all the inthe SDK documentation Transform Panel settings are erroneously still listed under lensCorrectionPanel.
What a great way to make things harder for newcomers.
Anyway this is how I wrote the script first:
local LrDevelopController = import "LrDevelopController"
local mode = LrDevelopController.resetToDefault ("PerspectiveVertical")
local mode = LrDevelopController.resetToDefault ("PerspectiveHorizontal")
local mode = LrDevelopController.resetToDefault ("PerspectiveRotate")
local mode = LrDevelopController.resetToDefault ("PerspectiveScale")
local mode = LrDevelopController.resetToDefault ("PerspectiveAspect")
local mode = LrDevelopController.resetToDefault ("PerspectiveX")
local mode = LrDevelopController.resetToDefault ("PerspectiveY")
local mode = LrDevelopController.resetToDefault ("PerspectiveUpright")
local mode = LrDevelopController.resetToDefault ("straightenAngle")
local mode = LrDevelopController.resetCrop()
This doesn't reset Crop in any way whatsoever but it does reset the Transform Panel.
Apparently LrDevelopController.resetCrop() doens't work in this context and must be used in a separate script on its own.
local LrDevelopController = import "LrDevelopController"
LrDevelopController.resetCrop()
I say apparently because in reality it is sufficient to write a single line above LrDevelopController.resetCrop() and BOTH reset Crop and reset Transform can be achieved in one code.
So I wrote this:
local LrDevelopController = import "LrDevelopController"
local mode = LrDevelopController.resetToDefault ("PerspectiveVertical")
local mode = LrDevelopController.resetToDefault ("PerspectiveHorizontal")
local mode = LrDevelopController.resetToDefault ("PerspectiveRotate")
local mode = LrDevelopController.resetToDefault ("PerspectiveScale")
local mode = LrDevelopController.resetToDefault ("PerspectiveAspect")
local mode = LrDevelopController.resetToDefault ("PerspectiveX")
local mode = LrDevelopController.resetToDefault ("PerspectiveY")
local mode = LrDevelopController.resetToDefault ("PerspectiveUpright")
local mode = LrDevelopController.resetToDefault ("straightenAngle")
LrDevelopController.setValue ("CropAngle", mode == 0)
local mode = LrDevelopController.resetCrop()
Unfortunately an extras tep for the Set Crop Angle will be recorded in history should the Crop Angle be other than 0...I tried to group them into one step with LrDevelopController.setMultipleAdjustmentThreshold() but to no avail.
So I wrote the following and it works (only one history step will be added and both Crop and Transform will be reset)
local LrDevelopController = import "LrDevelopController"
local mode = LrDevelopController.resetToDefault ("PerspectiveVertical")
local mode = LrDevelopController.resetToDefault ("PerspectiveHorizontal")
local mode = LrDevelopController.resetToDefault ("PerspectiveRotate")
local mode = LrDevelopController.resetToDefault ("PerspectiveScale")
local mode = LrDevelopController.resetToDefault ("PerspectiveAspect")
local mode = LrDevelopController.resetToDefault ("PerspectiveX")
local mode = LrDevelopController.resetToDefault ("PerspectiveY")
local mode = LrDevelopController.resetToDefault ("PerspectiveUpright")
local mode = LrDevelopController.resetToDefault ("straightenAngle")
LrDevelopController.setProcessVersion ("ProcessVersion 6")
local mode = LrDevelopController.resetCrop()
What is absurd and non intutive is that the penultimate line (as the above proves) can have nothing to do with Cropping.
One can even write LrDevelopController.setValue ("Exposure2012", mode == 0) and the LrDevelopController.resetCrop() will suddenly works in the same code alongside resetting transform.
This is most weird.
A bug or for some reason this is per design?
.
Clearly a bug in LrDevelopController -- another race condition. The simplest workaround is to add a 0.1 second delay before resetting the crop:
local LrDevelopController = import "LrDevelopController"
local LrTasks = import "LrTasks"
LrTasks.startAsyncTask (function ()
LrDevelopController.resetToDefault ("PerspectiveVertical")
LrDevelopController.resetToDefault ("PerspectiveHorizontal")
LrDevelopController.resetToDefault ("PerspectiveRotate")
LrDevelopController.resetToDefault (
...
Copy link to clipboard
Copied
Clearly a bug in LrDevelopController -- another race condition. The simplest workaround is to add a 0.1 second delay before resetting the crop:
local LrDevelopController = import "LrDevelopController"
local LrTasks = import "LrTasks"
LrTasks.startAsyncTask (function ()
LrDevelopController.resetToDefault ("PerspectiveVertical")
LrDevelopController.resetToDefault ("PerspectiveHorizontal")
LrDevelopController.resetToDefault ("PerspectiveRotate")
LrDevelopController.resetToDefault ("PerspectiveScale")
LrDevelopController.resetToDefault ("PerspectiveAspect")
LrDevelopController.resetToDefault ("PerspectiveX")
LrDevelopController.resetToDefault ("PerspectiveY")
LrDevelopController.resetToDefault ("PerspectiveUpright")
LrTasks.sleep (0.1)
LrDevelopController.resetCrop()
end)
Perhaps a more robust method is to use catalog:getDevelopSettings(), set or clear the appropriate fields, then do catalog:applyDevelopSettings(). But that's more involved.
Copy link to clipboard
Copied
Thanks John, that script with the sleep also works but it still adds 2 history steps.
Ultimately I decided to use the following method that creates only one history step, the familiar Multiple Settings step:
local LrDevelopController = import "LrDevelopController"
LrDevelopController.setValue ("PerspectiveVertical", mode == 0)
LrDevelopController.setValue ("PerspectiveHorizontal", mode == 0)
LrDevelopController.setValue ("PerspectiveRotate", mode == 0.0)
LrDevelopController.setValue ("PerspectiveAspect", mode == 0)
LrDevelopController.setValue ("PerspectiveScale", mode == 100)
LrDevelopController.setValue ("PerspectiveX", mode == 0)
LrDevelopController.setValue ("PerspectiveY", mode == 0)
LrDevelopController.setValue ("PerspectiveUpright", mode == 0)
LrDevelopController.setValue ("PerspectiveVertical", mode == 0)
LrDevelopController.setValue ("CropAngle", mode == 0)
LrDevelopController.setValue ("CropBottom", mode == 1)
LrDevelopController.setValue ("CropLeft", mode == 0)
LrDevelopController.setValue ("CropRight", mode == 1)
LrDevelopController.setValue ("CropTop", mode == 0)
It can only be ran in develop though.
I believe you mean to use photo:getDevelopSettings() and photo:applyDevelopSettings not catalog:getDevelopSettings()
With that method I could reset both Crop and Transform from any module but I generally need to see the "before and after" via history preview so using a script from develop is fine for me.
Bottom line: it is incredibly frustrating that one cannot use the relative API calls and group them together without problems.
I am at my very first step at writing scripts and I could find a workaround that delivers one histry step ONLY because I know the settings well.
A newcomer will unlikely ever think of using LrDevelopController.setValue and use the provided reset API.
.Thanks for the input and help.
Copy link to clipboard
Copied
Actually things are more complex than I thought.
The scripts I created with LrDevelopController.setValue works sometimes BUT other times totally doesn't work.
Only the script with LrTask.sleep seems to work all the times BUT it still adds 2 history steps.
Copy link to clipboard
Copied
"it is incredibly frustrating that one cannot use the relative API calls and group them together without problems."
I think the underlying cause is that LR internally was implemented to be highly asynchronous, so the user could initiate an action without waiting for the previous action to complete fully. Such asynchronicity would help make the user interface feel more responsive in a heavyweight app like LR where many of the operations take a relatively long time.
LrDevelopController was provided primarily as a way for MIDI controllers could be connected to LR, and the methods provided in LrDevelopController correspond directly to sliders, buttons, and actions in Develop. So adjusting a MIDI control calls just one method in LrDevelopController, and there is a relatively long pause before the user adjusts another control. But LrDevelopController doesn't provide any method for ensuring that previously invoked method completes before it tries to execute the next one.
So when you put multiple actions together in a script, there can be these race conditions. They haven't been reported before since most uses of LrDevelopController has been for MIDI controllers, with user pauses between each method invocation.
Copy link to clipboard
Copied
@John R Ellis yes I think that MIDI users unlikely ever face any of this since they invoke an API at the time rahter than several of them together.
This said Develop Preset can change multiple settings at the same time no problems.
The LrTask.sleep fixes the issues but still I can't totally explain why LrDevelopController.setMultipleAdjustmentThreshold() doesn't work and these calls cannot be grouped into one history step.
It should work.
P.s.
On the other hand I successfully created a "Reset Curves" script doesn't reset Parametric (a missing option) so not all calls result in a race condition.
Copy link to clipboard
Copied
" I can't totally explain why LrDevelopController.setMultipleAdjustmentThreshold() doesn't work and these calls cannot be grouped into one history step."
I think it's the same root cause as this previous bug report: