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();