Skip to main content
Known Participant
November 5, 2022
Answered

FlipX of brush using script

  • November 5, 2022
  • 5 replies
  • 1000 views

Hi! This should be really simple, all I need to do is toggle flipX (in Brush Properties) using a script.

This was my attempt:

var desc = new ActionDescriptor();
desc.putBoolean(stringIDToTypeID('flipX'), true);
executeAction(desc);

It brings an error for line 3 saying a numeric value is required.

 

I tried some code from this link: https://community.adobe.com/t5/photoshop-ecosystem-discussions/brush-kind-tools-spacing-is-always-25-by-script/m-p/8201506

 

Which works, but switches to the Airbrush instead of the brush I currently have. Any help? 🙂

This topic has been closed for replies.
Correct answer jazz-y
var s2t = stringIDToTypeID;

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('currentToolOptions'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
var tool = executeActionGet(r).getObjectValue(p);

if (tool.hasKey(s2t('brush'))) {
    var brush = tool.getObjectValue(s2t('brush'));

    brush.putBoolean(s2t('flipX'), true);
    tool.putObject(s2t('brush'), s2t('computedBrush'), brush);

    (r = new ActionReference()).putClass(s2t(currentTool));
    (d = new ActionDescriptor()).putReference(s2t("target"), r);
    d.putObject(s2t("to"), s2t("target"), tool);
    executeAction(s2t("set"), d, DialogModes.NO);
}

5 replies

jazz-yCorrect answer
Legend
November 7, 2022
var s2t = stringIDToTypeID;

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('currentToolOptions'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
var tool = executeActionGet(r).getObjectValue(p);

if (tool.hasKey(s2t('brush'))) {
    var brush = tool.getObjectValue(s2t('brush'));

    brush.putBoolean(s2t('flipX'), true);
    tool.putObject(s2t('brush'), s2t('computedBrush'), brush);

    (r = new ActionReference()).putClass(s2t(currentTool));
    (d = new ActionDescriptor()).putReference(s2t("target"), r);
    d.putObject(s2t("to"), s2t("target"), tool);
    executeAction(s2t("set"), d, DialogModes.NO);
}
pixxxelschubser
Community Expert
Community Expert
November 7, 2022

Hi @jazz-y,

you are one of the few I have pinned my hopes on.

😉

 

Your code works for me. Let's wait and see if the OP gets back on that too.

pixxxelschubser
Community Expert
Community Expert
November 6, 2022

Sorry, but the code seems to be a dead end. It always changes the tool.

 

I don't have the experience to recreate it and I don't have the time to adapt it to the tool currently in use.

Maybe someone else will find a suitable solution.

pixxxelschubser
Community Expert
Community Expert
November 5, 2022

In this case you can permanent "disable" --> comment out the two following lines:

if (Hardness == undefined) Hardness = brushDesc.getDouble(stringIDToTypeID('hardness'));    

and

desc1.putDouble(stringIDToTypeID('hardness'), Hardness);

 

Known Participant
November 5, 2022

I already tried that, it doesn't work. It just switches to the airbrush.

pixxxelschubser
Community Expert
Community Expert
November 5, 2022

This was not described in your original post.


Please say exactly what you have.

And please say exactly what you want.

(At the best with one or two additional screenshots)

Known Participant
November 5, 2022

I just want a script that flips X of any brush.

 

pixxxelschubser
Community Expert
Community Expert
November 5, 2022

Do you have experience with AM code programming?

No? Then you should definitely use the complete code from the linked topic!

 

Then it will work as desired.


//        Features(Diameter,Hardness,Angle,Roundness,Spacing,Flipy,Flipx) 

//setBrushFeatures(undefined,undefined,undefined,undefined,undefined,undefined,undefined); 

//setBrushFeatures(undefined,undefined,undefined,undefined,undefined,1,0);  //FlipY
setBrushFeatures(undefined,undefined,undefined,undefined,undefined,0,1);  //FlipX

//setBrushFeatures(13,0,0,100,25,0,0);       //Adobe Defaults 
//setBrushFeatures(13,0,0,100,25,true,true); //Diameter,Hardness,Angle,Roundness,Spacing,Flipy,Flipx 
//setBrushFeatures(13,0,0,100,25,1,0);       //Diameter,Hardness,Angle,Roundness,Spacing,Flipy,Flipx      
//setBrushFeatures(13,0,0,100,25,0);         //Diameter,Hardness,Angle,Roundness,Spacing,Flipy 
//setBrushFeatures(13,0,0,100,1);            //Diameter,Hardness,Angle,Roundness,Spacing 
//setBrushFeatures(13,0,0,50);               //Diameter,Hardness,Angle,Roundness 
//setBrushFeatures(13,0,45);                 //Diameter,Hardness,Angle 
//setBrushFeatures(13,50);                   //Diameter,Hardness 
//setBrushFeatures(25);                        //Diameter 

//==============================================================================================//

function setBrushFeatures (Diameter,Hardness,Angle,Roundness,Spacing,Flipy,Flipx) {  
    //A Brush tool must be the current tool
    if (!app.toolSupportsBrushes(app.currentTool)) selectBrush();  //CC 2014
    var ref = new ActionReference();  
    ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );  
    var appDesc = executeActionGet(ref);  
    var toolDesc = appDesc.getObjectValue(stringIDToTypeID('currentToolOptions'));  
    var brushDesc = toolDesc.getObjectValue(stringIDToTypeID('brush'));  
    if (Diameter == undefined) Diameter = brushDesc.getDouble(stringIDToTypeID('diameter'));  
    if (Hardness == undefined) Hardness = brushDesc.getDouble(stringIDToTypeID('hardness'));  
    if (Angle == undefined ) Angle = brushDesc.getDouble(stringIDToTypeID('angle'));  
    if (Roundness  == undefined) Roundness = brushDesc.getDouble(stringIDToTypeID('roundness'));  
    if (Spacing == undefined) Spacing = brushDesc.getDouble(stringIDToTypeID('spacing'));  
    if (Flipy == undefined) Flipy = brushDesc.getBoolean(stringIDToTypeID('flipY'));  
    if (Flipx == undefined) Flipx = brushDesc.getBoolean(stringIDToTypeID('flipX')); 
    var desc = new ActionDescriptor();  
    var ref = new ActionReference();  
    ref.putEnumerated( charIDToTypeID( "Brsh" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );  
    desc.putReference( charIDToTypeID( "null" ), ref );  
    var desc1 = new ActionDescriptor();  
    desc1.putDouble(stringIDToTypeID('diameter'), Diameter);  
    desc1.putDouble(stringIDToTypeID('hardness'), Hardness);  
    desc1.putDouble(stringIDToTypeID('angle'), Angle);  
    desc1.putDouble(stringIDToTypeID('roundness'), Roundness);  
    desc1.putUnitDouble( stringIDToTypeID('spacing'), charIDToTypeID('#Prc'), Spacing);  
    desc1.putBoolean(stringIDToTypeID('flipY'), Flipy);  
    desc1.putBoolean(stringIDToTypeID('flipX'), Flipx);  
    desc.putObject( stringIDToTypeID('to'), charIDToTypeID( "Brsh" ), desc1 );  
    executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );  
} 

function selectBrush() {
    //select brush scriptlistener code
    var idslct = charIDToTypeID( "slct" );
    var desc12 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
    var ref8 = new ActionReference();
    var idPbTl = charIDToTypeID( "PbTl" );
    ref8.putClass( idPbTl );
    desc12.putReference( idnull, ref8 );
    executeAction( idslct, desc12, DialogModes.NO );
}

 

Known Participant
November 5, 2022

This doesn't seem to work with brushes that have the hardness setting greyed out.