• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

FlipX of brush using script

Explorer ,
Nov 05, 2022 Nov 05, 2022

Copy link to clipboard

Copied

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...

 

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

TOPICS
Actions and scripting , Windows

Views

122

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 07, 2022 Nov 07, 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 =
...

Likes

Translate

Translate
Community Expert ,
Nov 05, 2022 Nov 05, 2022

Copy link to clipboard

Copied

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

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 05, 2022 Nov 05, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 05, 2022 Nov 05, 2022

Copy link to clipboard

Copied

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)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 05, 2022 Nov 05, 2022

Copy link to clipboard

Copied

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

LukasKawalec_0-1667686819524.png

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 05, 2022 Nov 05, 2022

Copy link to clipboard

Copied

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

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 05, 2022 Nov 05, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 05, 2022 Nov 05, 2022

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2022 Nov 07, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2022 Nov 07, 2022

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

Works perfectly, thank you very much. So much code to do such a simple thing, although I imagine some of it is to get around the brush not having hardness, I'm not sure. AM code is a funny thing 😛

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

LATEST

In fact, this code is similar to what the @pixxxelschubser wrote above.

The difference is that I save all the current brush settings to a variable, change flipX property, and write the brush variable back to the tool settings. The code above tries to completely recreate the brush based on a hard-coded set of parameters, and accordingly if the active brush contains more parameters (for example, sampling data for mask-based artistic brushes) or less (as we found, the brush may not have a hardness parameter), then this leads to unexpected results.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines