Skip to main content
Oleqsa
Known Participant
October 18, 2021
Answered

PS Script to switch Content-Aware vs Proximity Match in Spot Heal Tool and Patch tool question

  • October 18, 2021
  • 1 reply
  • 2541 views

I wrote a script to switch source sampling type for spot healing tool and patch tool between content-aware and proximity match.
It does switch the setting, but for some reason also turns on scattering for those tools.
And if i write a script that switches some tool setting the same way it switches some other stuff as well.
It's not visible on other tools, but spot healing tool.
I can add a line to set scattering to off manually, but i'd rather know why it happens and how to avoid it.
So what am i doing wrong here?

function checkCTOoption(charString){
    var ref = new ActionReference();
        ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));
        ref.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
    if (app.currentTool=="spotHealingBrushTool"){
        return executeActionGet(ref).getObjectValue(stringIDToTypeID("currentToolOptions")).getEnumerationValue(charIDToTypeID(charString));
    } else if ( app.currentTool=="patchSelection" ){
        return executeActionGet(ref).getObjectValue(stringIDToTypeID("currentToolOptions")).getBoolean(stringIDToTypeID(charString));
    } else {}
}
// get current tool options object
function getCTO(){
    var ref = new ActionReference();
        ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));
        ref.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        return executeActionGet(ref).getObjectValue(stringIDToTypeID("currentToolOptions"));
}
// setting currentToolOptions with options array
function setCTO( options ){
    var desc = new ActionDescriptor();
        var ref = new ActionReference();
            ref.putClass( stringIDToTypeID( app.currentTool ) );
        desc.putReference( stringIDToTypeID( "target" ), ref );
        // getting current tool options
        var ctoObj = getCTO();
            if ( app.currentTool=="spotHealingBrushTool" ){
                ctoObj.putEnumerated( charIDToTypeID( options[0] ), charIDToTypeID( "SmmT" ), charIDToTypeID( options[1] ) );
            } else if ( app.currentTool=="patchSelection" ) {
                ctoObj.putBoolean( stringIDToTypeID( options[0] ), options[1] );
            } else {}
            // fix i need to add cause it turnes on by itself for some reason:
            // ctoObj.putBoolean( stringIDToTypeID( "useScatter" ), false ); 
        desc.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "currentToolOptions" ), ctoObj );
    executeAction( stringIDToTypeID( "set" ), desc, DialogModes.NO );
}
// switching currentToolOptions if it's one of the tools, ignoring otherwise
function switchCTO (){
    if ( app.currentTool=="spotHealingBrushTool" ){
        if ( checkCTOoption("SmmS")==(charIDToTypeID("CntW")) ){
            setCTO( ["SmmS","PrxM"] );
        } else {
            setCTO( ["SmmS","CntW"] );
        }
    }
    else if ( app.currentTool=="patchSelection" ){
        if ( checkCTOoption("contentAware", true)==false ){
            setCTO( ["contentAware", true] );
        } else {
            setCTO( ["contentAware", false] );
        }
    }
    else {
        // if other tools, do nothing
    }
}
switchCTO();
This topic has been closed for replies.
Correct answer jazz-y

I wanted to move this thread to Bugs but then I thought maybe you'll show up and find some workaround. You came indeed 🙂 (Un)fortunately jazz-y already made a topic in bugs section.


A workaround is to check if the tool has the "useScatter" and "brush" parameters. If there is no "useScatter", but there is a "brush," then it is one of the painting tools potentially affected by this bug. You can safely write useScatter = false to its descriptor and everything will be fine.

You can delete that topic in the "bugs" section and put this one there. Although I tried to describe the problem there in as much detail as possible (as @r-bin noticed, it concerns not only scripts, but also presets, i.e. ordinary users also face it). I analyzed my old scripts and found I had this problem already. Previously, the bug was related to more tools. This has been fixed at the moment.

1 reply

Legend
October 18, 2021

I have met such a problem. Now, not at the computer, to remember what I did in the end, but, it seems, I just saved descriptor with all the tool settings to a variable, changed a separate parameter inside this desc, then assigned it (with all the settings) to the tool.

Oleqsa
OleqsaAuthor
Known Participant
October 18, 2021

Well, i kinda do the same thing with 

 

var ctoObj = getCTO();
ctoObj.put...

 

but the problem here is - Spot Healing Tool doesn't have scattering setting, and the currentToolOptions actionDescriptor i am getting with that function should not have it either.
So scattering must be added there from somewhere else and i have no idea where, cause i have it turned off on every tool and i have no tool presets with it.
I will try to log that descriptor and read through it to see what it actually has inside.
Really strange stuff.

 

 

Just logged the Descriptor that is getting sent to executeAction set function and it does not have scattering, but when action executes, it's (scattering) turned on under the hood, but still no sign of it in the currentToolOptions descriptor.
I am logging full descriptor into a txt file with everything inside (apart from raw data and file path that can be there), so if it's there somewhere, i have no idea where.
Once i manually add scattering = false, all works fine, but it's not a good solution cause there might be other stuff turned on or off as well that i can't see and i don't want anything random there.

Legend
October 18, 2021

I found my script. There is the same problem. I have not been able to solve it. The most interesting thing is that if you change the tool settings once, then scattering stays with it forever (until you manually assign useScatter = false). It looks like a bug.