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

Is it possible to script brush opacity?

Explorer ,
Oct 02, 2015 Oct 02, 2015

Copy link to clipboard

Copied

I would like to script the current brush's opacity to 20%. Have done a lot of googling but cant find a clear answer. Is this possible?

On a Mac with Photoshop CS6

TOPICS
Actions and scripting

Views

3.8K

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

Explorer , Oct 02, 2015 Oct 02, 2015

from script listener.  The following code will create the preset.  I just tested it in CS6 OSX

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

var idMk = charIDToTypeID( "Mk  " );

    var desc4 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref2 = new ActionReference();

        var idBrsh = charIDToTypeID( "Brsh" );

        ref2.putClass( idBrsh );

    desc4.putReference( idnull, ref2 );

    var idUsng = charIDToTypeID( "Usng" );

        var ref3 = new ActionR

...

Votes

Translate

Translate
Adobe
Explorer ,
Oct 02, 2015 Oct 02, 2015

Copy link to clipboard

Copied

I guess after more googling the only way is to select a tool preset. Problem is that I want to share the action with coworkers not having to worry about if they have the same tool-presets as me (or rename/delete them).

 

Would it be possible to modify this script to set a tool preset for brus 150px and opacity 20% ? I can try myself but I am kind of new in scripting so I need som guidance.

 

Script and burn tool

Votes

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 ,
Oct 02, 2015 Oct 02, 2015

Copy link to clipboard

Copied

from script listener.  The following code will create the preset.  I just tested it in CS6 OSX

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

var idMk = charIDToTypeID( "Mk  " );

    var desc4 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref2 = new ActionReference();

        var idBrsh = charIDToTypeID( "Brsh" );

        ref2.putClass( idBrsh );

    desc4.putReference( idnull, ref2 );

    var idUsng = charIDToTypeID( "Usng" );

        var ref3 = new ActionReference();

        var idPrpr = charIDToTypeID( "Prpr" );

        var idCrnT = charIDToTypeID( "CrnT" );

        ref3.putProperty( idPrpr, idCrnT );

        var idcapp = charIDToTypeID( "capp" );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idTrgt = charIDToTypeID( "Trgt" );

        ref3.putEnumerated( idcapp, idOrdn, idTrgt );

    desc4.putReference( idUsng, ref3 );

executeAction( idMk, desc4, DialogModes.NO );

Votes

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 ,
Oct 02, 2015 Oct 02, 2015

Copy link to clipboard

Copied

Have you tried using the script listener pluging? ADOBE PHOTOSHOP SCRIPTING. It will record everything you do in photoshop, except changing zoom levels. Turn it on, turn your opacity down, turn it off. Check your desktop for a log file named something like "Scriptlistener.log" and inside there will be the code to do whatever you've just done inside of photoshop.

Votes

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
Adobe Employee ,
Sep 15, 2016 Sep 15, 2016

Copy link to clipboard

Copied

Votes

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 ,
Sep 15, 2016 Sep 15, 2016

Copy link to clipboard

Copied

Thank you Tom

Being a cut  and paste hacker like I am this may help others a little collection

// SetPaintBrush Script 2016 Tom Ruark and others like Mike Hale (RIP) cut and paste  by JJMack

// Set the options for the paint brush tool like on the tool option bar

// Round Brush Tip Features Diameter,Hardness,Angle,Roundness,Spacing,Flipy,Flipx

// blend modes, opacity, flow and pressure control

// Note: can also retrieve round brush tip features

// So if you retrieve the current brush tip features

// you can select Brush Presets to toggle while brush dynamic setting

// and the restore the tip features so presets does not size shape hardness etc

if (documents.length == 0) { var d = documents.add();}

else { var d = activeDocument;}

// At least two layers so behind and clear are available

if (d.layers.length == 1) { d.artLayers.add(); }

setTool('paintbrushTool');

// blend modes for paint brush

var bmsS = ["normal", "dissolve", "behind", "clearEnum",

            "darken", "multiply", "colorBurn", "linearBurn", "darkerColor",

            "lighten", "screen", "colorDodge", "linearDodge", "lighterColor",

            "overlay", "softLight", "hardLight", "vividLight", "linearLight", "pinLight", "hardMix",

            "difference", "exclusion", "blendSubtraction", "blendDivide",

            "hue", "saturation", "color", "luminosity",  ];

try {

  /* parameters (Diameter,Hardness,Angle,Roundness,Spacing,Flipy,Flipx) all are required

  Diameter  range 1 to 5000

  Hardness  range 0 to 100

  Angle     range 0 to + or - 180

  Roundness range 1 to 100

  Spacing   range 1 to 1000

  Flipy     range 0 or 1 false or true

    Flipx     range 0 or 1 false or true

  */

  setBrushFeatures(13,0,0,100,25,0,0);       //Adobe Defaults

  // parameters (mode character string, opacity %, flow %, penopacity boolean, pensize boolean, penair boolean) all are required

  SetPaintBrush(bmsS[0],100,100,0,0,0);     // Adobe Defaults

  /* Toggle Brtsh dynamivcs with  ON  and OFF  brtsh presets this is commented out the Preset need to be made

  var PresetName1 = "Brush Dynamics ON";    // Name of tool preset

  var PresetName2 = "Brush Dynamics OFF";   // Name of tool preset

  var PT = $.getenv("PanelDynamics");

  var saveFeatures = getBrushFeatures();

  // CHECK TOOL PRESET Dynamics STATE

  if(PT == null || PT == "OFF"){

  $.setenv("PanelDynamics","ON");

  SelectToolPreset(PresetName2);

  }

  else{

  $.setenv("PanelDynamics","OFF");

  SelectToolPreset(PresetName1);

  }

  setBrushFeatures(saveFeatures[0],saveFeatures[1],saveFeatures[2],saveFeatures[3],saveFeatures[4],saveFeatures[5],saveFeatures[6]);

  */

}

catch(e){

  //Something went wrong

  alert(e + ': on line ' + e.line, 'Script Error', true);

  //alert ("An unexpected error occurred and the script did not complete!");

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////

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

function setTool(tool) {

  var desc9 = new ActionDescriptor();

  var ref7 = new ActionReference();

  ref7.putClass( app.stringIDToTypeID(tool) );

  desc9.putReference( app.charIDToTypeID('null'), ref7 );

  executeAction( app.charIDToTypeID('slct'), desc9, DialogModes.NO );

  }

function getBrushFeatures (){

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

    var currDiameter = brushDesc.getDouble(stringIDToTypeID('diameter')); 

    var currHardness = brushDesc.getDouble(stringIDToTypeID('hardness')); 

    var currAngle = brushDesc.getDouble(stringIDToTypeID('angle')); 

    var currRoundness = brushDesc.getDouble(stringIDToTypeID('roundness')); 

    var currSpacing = brushDesc.getDouble(stringIDToTypeID('spacing')); 

    var currFlipy = brushDesc.getBoolean(stringIDToTypeID('flipY')); 

    var currFlipx = brushDesc.getBoolean(stringIDToTypeID('flipX'));

  var currentFeatures = new Array( currDiameter, currHardness, currAngle, currRoundness, currSpacing, currFlipy, currFlipx );

    return currentFeatures

}

function setBrushFeatures (Diameter,Hardness,Angle,Roundness,Spacing,Flipy,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 SetPaintBrush(mode,opacity,flow,penopacity,pensize,penair) {

  var idset = stringIDToTypeID( "set" );

  var desc226 = new ActionDescriptor();

  var idnull = stringIDToTypeID( "null" );

  var ref170 = new ActionReference();

    var idPbTl = stringIDToTypeID( "paintbrushTool" );

    ref170.putClass( idPbTl );

    desc226.putReference( idnull, ref170 );

    var id12 = stringIDToTypeID( "to" );

    var desc5 = new ActionDescriptor();

    // opacity

    var id13 = stringIDToTypeID( "opacity" );

    var id14 = stringIDToTypeID( "percentUnit" );

  desc5.putUnitDouble( id13, id14, opacity );

    // blend mode

    var id15 = stringIDToTypeID( "mode" );

    var id16 = stringIDToTypeID( "blendModel" );

  var id17 = stringIDToTypeID( mode );

    desc5.putEnumerated( id15, id16, id17 );

    // flow

    var id19 = stringIDToTypeID( "flow" );

  desc5.putUnitDouble( id19, id14, flow );

    // pressure for opacity

    desc5.putBoolean( stringIDToTypeID( "usePressureOverridesOpacity" ), penopacity );

    // pressure for size

    desc5.putBoolean( stringIDToTypeID( "usePressureOverridesSize" ), pensize );

    // enable air brush

    desc5.putBoolean( stringIDToTypeID( "repeat" ), penair );

    var id18 = stringIDToTypeID( "null" );

    desc226.putObject( id12, id18, desc5 );

  executeAction( idset, desc226, DialogModes.NO );

  }

function SelectToolPreset(PresetName) {

  var idslct = charIDToTypeID( "slct" );

  var desc14 = new ActionDescriptor();

  var idnull = charIDToTypeID( "null" );

  var ref10 = new ActionReference();

  var idtoolPreset = stringIDToTypeID( "toolPreset" );

  ref10.putName( idtoolPreset, PresetName);

  desc14.putReference( idnull, ref10 );

  executeAction( idslct, desc14, DialogModes.NO );

  }

JJMack

Votes

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
Participant ,
Aug 29, 2018 Aug 29, 2018

Copy link to clipboard

Copied

This is really useful, but where did you find all those string IDs in the getBrushFeatures() function? 

brush

diameter

hardness

etc

Yes, they make sense, but so does "brushDiameter" instead of "diameter" and it's hard to know what PS is looking for with string IDs.

Votes

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
LEGEND ,
Aug 29, 2018 Aug 29, 2018

Copy link to clipboard

Copied

You can for example find them in some brush preset after saving it to disk and reading its binaries.

Votes

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
Participant ,
Aug 29, 2018 Aug 29, 2018

Copy link to clipboard

Copied

I'm not looking for presets, I don't think.  It looks like the getBrushFeatures() function is grabbing these string IDs from "currentToolOptions" and I'm trying to find the current tool options for several different tools, not just brushes.

Votes

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
LEGEND ,
Aug 29, 2018 Aug 29, 2018

Copy link to clipboard

Copied

Then start from this:

sTT = stringIDToTypeID; (ref = new ActionReference()).putProperty

(sTT('property'), sTT('tool')), ref.putClass(sTT('application'))

executeActionGet(ref).getObjectValue(sTT('currentToolOptions'))

Votes

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 ,
Jan 20, 2019 Jan 20, 2019

Copy link to clipboard

Copied

JJMack, Thank you for such a helpful script! But I have a trouble with Scattering. It's automatically toggle on with setPaintBrush function. Have no idea why and how to fix that... Maybe you can advice?

Hooray! I solved. Added this code after desc5.putUnitDouble in //flow section of setPaintBrush function:

  // scattering

  var id191 = stringIDToTypeID( "scatter" );

  desc5.putUnitDouble( id191, id14, scatter );

Votes

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 ,
Jan 20, 2019 Jan 20, 2019

Copy link to clipboard

Copied

The function should not chage the brush Scattering from what the I see function parameters

// parameters (mode character string, opacity %, flow %, penopacity boolean, pensize boolean, penair boolean) all are required 

function SetPaintBrush(mode,opacity,flow,penopacity,pensize,penair)

Mode blendind type, Opacity how opaque, Flow rate

seems to set and the others seem to be True/False for the brush tool Option bar pen controls

Opacity presure, Size transfer pen controled, and Airbrush mode

The three toggles are Shape Dytnamics, Transfer and Buildup

The Current brush Scattering should not change

I see nothing in the function action manager coder that address Scattering

var idset = stringIDToTypeID( "set" ); 

  var desc226 = new ActionDescriptor(); 

  var idnull = stringIDToTypeID( "null" ); 

  var ref170 = new ActionReference(); 

    var idPbTl = stringIDToTypeID( "paintbrushTool" ); 

    ref170.putClass( idPbTl ); 

    desc226.putReference( idnull, ref170 ); 

    var id12 = stringIDToTypeID( "to" ); 

    var desc5 = new ActionDescriptor(); 

    // opacity 

    var id13 = stringIDToTypeID( "opacity" ); 

    var id14 = stringIDToTypeID( "percentUnit" ); 

  desc5.putUnitDouble( id13, id14, opacity ); 

    // blend mode 

    var id15 = stringIDToTypeID( "mode" ); 

    var id16 = stringIDToTypeID( "blendModel" ); 

  var id17 = stringIDToTypeID( mode ); 

    desc5.putEnumerated( id15, id16, id17 ); 

    // flow 

    var id19 = stringIDToTypeID( "flow" ); 

  desc5.putUnitDouble( id19, id14, flow ); 

    // pressure for opacity 

    desc5.putBoolean( stringIDToTypeID( "usePressureOverridesOpacity" ), penopacity ); 

    // pressure for size 

    desc5.putBoolean( stringIDToTypeID( "usePressureOverridesSize" ), pensize ); 

    // enable air brush 

    desc5.putBoolean( stringIDToTypeID( "repeat" ), penair ); 

    var id18 = stringIDToTypeID( "null" ); 

    desc226.putObject( id12, id18, desc5 ); 

  executeAction( idset, desc226, DialogModes.NO ); 

JJMack

Votes

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
LEGEND ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

LATEST

In JavaScripts you said "I currently have 1354 JavaScript files and I will be adding them here after I clean them up.", but after 6 years there are less than 10 uploaded scripts. Could you add some more?

Votes

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