Skip to main content
brian_p_dts
Community Expert
Community Expert
March 28, 2020
Answered

Setting Opacity and Feathering of a selected Brush via script

  • March 28, 2020
  • 1 reply
  • 649 views

Hi all - I am working on a script that relies on some preloaded brushes. From what I can gather (I'm traditionally an InDesign scripter), the only way to set opacity is through a preloaded brush. I do have a function in script that checks the brushes, where I'd like to set the opacity and feather weight of these brushes if they exist. I can't figure out how to Action Script it. Does anyone have any guidance? TIA. 

 

 

 

var hasBrushes = function(weight) {
  
  function checkStroked(enabled) {
    if (enabled != undefined && !enabled)
      return;
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putName(cTID('Brsh'), "Solid" + weight.toString() + "px"); 
    desc1.putReference(cTID('null'), ref1);
    executeAction(cTID('slct'), desc1, DialogModes.NO);
  };

  
  function checkDotted(enabled) {
    if (enabled != undefined && !enabled)
      return;
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putName(cTID('Brsh'), "Dotted" + weight.toString() + "px");
    desc1.putReference(cTID('null'), ref1);
    executeAction(cTID('slct'), desc1, DialogModes.NO);
  };

  try {
     checkStroked();
     checkDotted();
  catch(e) { return false; }
  return true;
}

 

 

This topic has been closed for replies.
Correct answer pixxxelschubser

Does that helps you a little?

// set brush opacity to 84 Procent

var brsh = new ActionDescriptor();
var ref = new ActionReference();
ref.putClass( charIDToTypeID('PbTl') );
brsh.putReference( charIDToTypeID('null'), ref );
var desc_br = new ActionDescriptor();
desc_br.putUnitDouble( charIDToTypeID('Opct'), charIDToTypeID('#Prc'), 84 );  // opacity
brsh.putObject( charIDToTypeID('T   '), charIDToTypeID('null'), desc_br );
executeAction( charIDToTypeID('setd'), brsh, DialogModes.NO );

1 reply

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
March 28, 2020

Does that helps you a little?

// set brush opacity to 84 Procent

var brsh = new ActionDescriptor();
var ref = new ActionReference();
ref.putClass( charIDToTypeID('PbTl') );
brsh.putReference( charIDToTypeID('null'), ref );
var desc_br = new ActionDescriptor();
desc_br.putUnitDouble( charIDToTypeID('Opct'), charIDToTypeID('#Prc'), 84 );  // opacity
brsh.putObject( charIDToTypeID('T   '), charIDToTypeID('null'), desc_br );
executeAction( charIDToTypeID('setd'), brsh, DialogModes.NO );
brian_p_dts
Community Expert
Community Expert
March 29, 2020

Worked perfectly. Thank you!