1 Reply Latest reply on Feb 26, 2017 10:02 PM by JJMack

    Change brush diameter - JSX script


      Hello all.


      I try to change brush diameter through a JSX script.

      I googled and found the following script in this forum.

      This code changes diameter, but it also changes selected brush as below.


      I don't know what's wrong.

      My environment is  Windows 7 with Photoshop CC 2015.



       function setBrushFeatures(Diameter) {  
        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( brushDesc.hasKey(stringIDToTypeID('sampledData'))){  
            var SampleData = brushDesc.getString(stringIDToTypeID('sampledData'));  
          var Name = brushDesc.getString(stringIDToTypeID('name'))  
        if (Diameter == undefined) Diameter = brushDesc.getDouble(stringIDToTypeID('diameter'));  
        var SampleIntr = brushDesc.getBoolean(charIDToTypeID('Intr'));  
        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);  
        if( brushDesc.hasKey(stringIDToTypeID('sampledData'))){  
          desc1.putString(stringIDToTypeID('sampledData'), SampleData);  
          desc1.putString(stringIDToTypeID('name'), Name);  
          desc1.putBoolean(charIDToTypeID('Intr'), SampleIntr);  
          var desc5 = new ActionDescriptor();  
          var idnull = charIDToTypeID( "null" );  
              var ref3 = new ActionReference();  
              var idBrsh = charIDToTypeID( "Brsh" );  
              var idOrdn = charIDToTypeID( "Ordn" );  
              var idTrgt = charIDToTypeID( "Trgt" );  
              ref3.putEnumerated( idBrsh, idOrdn, idTrgt );  
          desc5.putReference( idnull, ref3 );  
        var idsampledBrush = stringIDToTypeID( "sampledBrush" );  
        desc5.putObject( charIDToTypeID( "T   " ), idsampledBrush, desc1 );  
        executeAction( charIDToTypeID( "setd" ), desc5, DialogModes.NO );  
      setBrushFeatures(24, )  


      Brush settings before running script.


      after running script.


        • 1. Re: Change brush diameter - JSX script
          JJMack Most Valuable Participant

          If you notice your before running the script image the brush has a fancy sample data brush tip from the appearance of the stroke preview.   As Far as I know only round brush tip diameter feature can be change via a Photoshop script.  Notice your  after the script has been run image the brush is now a round tip brush.


          I find action manger script code very hard to decipher because I do not know all the 4 bytes ID codes and I would need looked them up in Adobe book. It looks like the function first retrieves the current brush description and test if its a sampled brush  and tries to handle  the sample brush case. Newer version of Photoshop  also have mixer brush that such a script  would need to be able to handled. For what version of Photoshop was this script written?  There is not test for what Photoshop version is using the script in the script.  If you search this forum toy will find scripts you can use to change round tip brush features. And other script to handle brushes by cycling through brush tool presets. And  some information on custom brush palettes Photoshop addons