Skip to main content
C.Cella
Legend
January 30, 2024
Answered

Resetting both Crop and Transform Panel using API requires weird workaround.

  • January 30, 2024
  • 1 reply
  • 658 views

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?

 

 

.

 

 

This topic has been closed for replies.
Correct answer johnrellis

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.

1 reply

johnrellis
johnrellisCorrect answer
Legend
January 31, 2024

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.

C.Cella
C.CellaAuthor
Legend
January 31, 2024

@johnrellis 

 

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.

 

 

 

C.Cella
C.CellaAuthor
Legend
January 31, 2024

@johnrellis 

 

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.