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

Increment Opacity and Flow

Guest
Aug 24, 2017 Aug 24, 2017

Copy link to clipboard

Copied

I'm trying to make a script to increment Opacity and Flow. I jumbled together the script fromRe: Is it possible to script brush opacity?  and Re: brush opacity for scripting

Opacity Increment:

  1. function SetPaintBrush(opacity) {   
  2.   var idset = stringIDToTypeID( "set" );   
  3.   var desc226 = new ActionDescriptor();   
  4.   var idnull = stringIDToTypeID( "null" );   
  5.   var ref170 = new ActionReference();   
  6.     var idPbTl = stringIDToTypeID( "paintbrushTool" );   
  7.     ref170.putClass( idPbTl );   
  8.     desc226.putReference( idnull, ref170 );   
  9.     var id12 = stringIDToTypeID( "to" );   
  10.     var desc5 = new ActionDescriptor();   
  11.     // opacity   
  12.     var id13 = stringIDToTypeID( "opacity" );   
  13.     var id14 = stringIDToTypeID( "percentUnit" );   
  14.   desc5.putUnitDouble( id13, id14, opacity );     
  15.     var id18 = stringIDToTypeID( "null" );   
  16.     desc226.putObject( id12, id18, desc5 );   
  17.   executeAction( idset, desc226, DialogModes.NO );   
  18.   } 
  19.  
  20.  
  21. function BrushOpacityGet() 
  22.   var ref = new ActionReference(); 
  23.   ref.putEnumerated(charIDToTypeID("capp"),  
  24.                     charIDToTypeID("Ordn"),  
  25.                     charIDToTypeID("Trgt"
  26.                     );  
  27.   var AD = executeActionGet(ref); 
  28.   AD = AD.getObjectValue(stringIDToTypeID("currentToolOptions")); 
  29.   return(AD.getInteger(stringIDToTypeID("opacity"))); 
  30.  
  31.  
  32. opacity = BrushOpacityGet(); 
  33. var op = opacity+5
  34. SetPaintBrush(op); 

Flow Increment:

  1. function SetPaintBrush(flow) {   
  2.   var idset = stringIDToTypeID( "set" );   
  3.   var desc226 = new ActionDescriptor();   
  4.   var idnull = stringIDToTypeID( "null" );   
  5.   var ref170 = new ActionReference();   
  6.     var idPbTl = stringIDToTypeID( "paintbrushTool" );   
  7.     ref170.putClass( idPbTl );   
  8.     desc226.putReference( idnull, ref170 );   
  9.     var id12 = stringIDToTypeID( "to" );   
  10.     var desc5 = new ActionDescriptor();   
  11.     // flow   
  12.     var id14 = stringIDToTypeID( "percentUnit" ); 
  13.     var id19 = stringIDToTypeID( "flow" );   
  14.   desc5.putUnitDouble( id19, id14, flow );   
  15.     var id18 = stringIDToTypeID( "null" );   
  16.     desc226.putObject( id12, id18, desc5 );   
  17.   executeAction( idset, desc226, DialogModes.NO );   
  18.   } 
  19.  
  20.  
  21. function BrushOpacityGet() 
  22.   var ref = new ActionReference(); 
  23.   ref.putEnumerated(charIDToTypeID("capp"),  
  24.                     charIDToTypeID("Ordn"),  
  25.                     charIDToTypeID("Trgt"
  26.                     );  
  27.   var AD = executeActionGet(ref); 
  28.   AD = AD.getObjectValue(stringIDToTypeID("currentToolOptions")); 
  29.   return(AD.getInteger(stringIDToTypeID("flow"))); 
  30.  
  31.  
  32. flow = BrushOpacityGet(); 
  33. var flo = flow+5
  34. SetPaintBrush(flo); 

It almost works, but there's two major issues on the script

1. It turns on Shape Dynamics and Scattering and turns off any other parameters (Transfer, Dual Brush, etc.)

2. The script is pretty slow the first time it runs

Anyone know what is causing this, and how to fix it?

Any help will be appreciated!

TOPICS
Actions and scripting

Views

1.1K

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
Engaged ,
Aug 24, 2017 Aug 24, 2017

Copy link to clipboard

Copied

Hi,

very likely problem #2 (the slowness of the first time run) is due to the fact that the BrushOpacityGet is getting the entire Application's descriptor (which contains lots of information that you don't really need). The following implementation gets the tool only, so it should be faster:

function BrushOpacityGet()   

{   

  var ref = new ActionReference();   

  ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("tool")); // Gets only the "tool"

  ref.putEnumerated(charIDToTypeID("capp"),    

                    charIDToTypeID("Ordn"),    

                    charIDToTypeID("Trgt")   

                    );    

  var AD = executeActionGet(ref);   

  AD = AD.getObjectValue(stringIDToTypeID("currentToolOptions"));   

  return(AD.getInteger(stringIDToTypeID("opacity")));   

}

Let me think about problem #1...

Davide

Davide Barranca - PS developer and author
www.ps-scripting.com

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
Engaged ,
Sep 11, 2017 Sep 11, 2017

Copy link to clipboard

Copied

Gelicider  schrieb

1. It turns on Shape Dynamics and Scattering and turns off any other parameters (Transfer, Dual Brush, etc.)

This is also a big problem for me. As I can see "Scattering" and "Smoothing" will be turned on, all others off.

I'm using this function (found in the forum here):

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

    }

It happens the same.

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
Contributor ,
Nov 16, 2017 Nov 16, 2017

Copy link to clipboard

Copied

LATEST

tomzagGelicider

I had same issue.

r-bin​ 's code at following thread seems working without resetting issue.

Thank you,

Naoki

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