3 Replies Latest reply on Jun 4, 2018 7:58 AM by SuperMerlin

    How to Set Current Tool Opacity to 100%?

    arteangelus Level 1

      Hello, I'm trying to set opacity of paint brush tool to 100%. I tried many ways but could not find it, I tried to record an action but it did not record. Then I installed scriptlistener and got script below but it does not work either. It throws an error at the last line ;

      executeAction( idtoolModalStateChanged, desc69, DialogModes.NO );


      Here is scriptlistener's output;


      var idtoolModalStateChanged = stringIDToTypeID( "toolModalStateChanged" );
          var desc69 = new ActionDescriptor();
          var idLvl = charIDToTypeID( "Lvl " );
          desc69.putInteger( idLvl, 0 );
          var idStte = charIDToTypeID( "Stte" );
          var idStte = charIDToTypeID( "Stte" );
          var idexit = stringIDToTypeID( "exit" );
          desc69.putEnumerated( idStte, idStte, idexit );
          var idTool = charIDToTypeID( "Tool" );
              var desc70 = new ActionDescriptor();
              var idIdnt = charIDToTypeID( "Idnt" );
              desc70.putString( idIdnt, """pntb""" );
              var idTtl = charIDToTypeID( "Ttl " );
              desc70.putString( idTtl, """Brush Tool""" );
          var idTool = charIDToTypeID( "Tool" );
          desc69.putObject( idTool, idTool, desc70 );
          var idKnd = charIDToTypeID( "Knd " );
          var idKnd = charIDToTypeID( "Knd " );
          var idPnt = charIDToTypeID( "Pnt " );
          desc69.putEnumerated( idKnd, idKnd, idPnt );
          var idkcanDispatchWhileModal = stringIDToTypeID( "kcanDispatchWhileModal" );
          desc69.putBoolean( idkcanDispatchWhileModal, true );
      executeAction( idtoolModalStateChanged, desc69, DialogModes.NO );


      I've searched but could not find an exact answer.

      (Note: In my main script I aim to create a work path point then apply a stroke with paint brush tool. So It would be still useful if there's a way to paint with a brush which has 100% opacity.)


      Thanks and Best Regards.

        • 1. Re: How to Set Current Tool Opacity to 100%?
          JJMack Most Valuable Participant

          Many things you can do in Photoshop are nor record-able in Actions. If something can not be recorded in an action the Scriplistener Plug-in will not record anything either for it record action manager code.   Adobe introduce tool recording a few release ago you may be able to record brush opacity changes with that feature. I do not use this feature for I do not find it useful for general work. It only woks well on same size documents.   However, if you install the scriptlistener plug-in Adobe will disable the tool recording feature.


          You best bet is to use Prush Presets Opacity setting should be recorded in  brush presets. You can select Brush presets in actions ant the selection will record in you action..

          • 2. Re: How to Set Current Tool Opacity to 100%?
            Pedro Cortez Marques Level 3
            ///////////////////////////////////////// Set Brush
            setBrushFeatures(170, 80,undefined,undefined,1,undefined,undefined);
            function setBrushFeatures(Diameter,Hardness,Angle,Roundness,Spacing,Flipy,Flipx) {
                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( charIDToTypeID( "T  " ), charIDToTypeID( "Brsh" ), desc1 );
                executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
            • 3. Re: How to Set Current Tool Opacity to 100%?
              SuperMerlin Level 5

              Modified code written by r-bin Photoshop CC 2018 only.


              #target Photoshop;
              function setOpacity(value) {    
              var ar = new ActionReference();    
              ar.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "tool" ) );    
              ar.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );    
              var ret = executeActionGet(ar);    
              var tmp = ret.getObjectValue(stringIDToTypeID("currentToolOptions"));    
              var tool = ret.getEnumerationType(stringIDToTypeID("tool"));
              var ad = new ActionDescriptor();    
              ar = new ActionReference(); 
              ar.putClass( tool );
              ad.putReference( charIDToTypeID( "null" ), ar );    
              if (value != undefined) tmp.putUnitDouble( stringIDToTypeID( "opacity" ), charIDToTypeID( "#Pxl" ), value ); 
              ad.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "Ordn" ), tmp );
              executeAction( charIDToTypeID( "setd" ), ad, DialogModes.NO );