Setting brush options

Discussion of the xtools Toolkit

Moderators: xbytor, DavideBarranca, Paul MR

pfaffenbichler

Setting brush options

Post by pfaffenbichler »

Thanks for replying and sorry if I start repeating Your own questions … 
ActionDecsriptors seem beyond my understanding.

But please allow me one more:
If I make an alert from »brushDesc.toStream()« for a sampled and a computed brush they produce differing texts as seen in attached jpg.
»sampledBrush« and »computedBrush« seem to be no keys though or at least the count of the descriptor doesn’t include them, so what are they?

Mike Hale

Setting brush options

Post by Mike Hale »

pfaffenbichler wrote:Thanks for replying and sorry if I start repeating Your own questions … 

Keep asking, maybe the way to solve this is by using toStream. I know I haven't had any luck using my approach.

From looking at all the code posted I would guess that »sampledBrush« and »computedBrush« are stringID for brush type. At least Paul used computedBrush in his code to write the descriptor back. I'm not sure where he got that. I am using the charID Brsh.

I just tried changing Brsh to sampledBrush using my code and it still reset the brush to computed.

Paul MR

Setting brush options

Post by Paul MR »

I wonder if anyone has managed to set the mode, opacity and flow of the selected brush?

Mike Hale

Setting brush options

Post by Mike Hale »

No, I would think the code should look something like this

Code: Select all   var ref = new ActionReference();
   ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
   var appDesc = executeActionGet(ref);
   var toolDesc = appDesc.getObjectValue(stringIDToTypeID('currentToolOptions'));
   toolDesc.putInteger(stringIDToTypeID( 'opacity'), 50 );
var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID('currentToolOptions') );
        ref.putEnumerated( charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
    desc.putReference( charIDToTypeID( "null" ), ref );
    desc.putObject( charIDToTypeID( "T   " ), stringIDToTypeID('currentToolOptions'), toolDesc );
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );   
   
Or
Code: Select all   var ref = new ActionReference();
   ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID('currentToolOptions') );
   ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
   var toolDesc = executeActionGet(ref).getString(stringIDToTypeID('currentToolOptions'));
   toolDesc.putInteger(stringIDToTypeID( 'opacity'), 50 );
var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID('currentToolOptions') );
        ref.putEnumerated( charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
    desc.putReference( charIDToTypeID( "null" ), ref );
    desc.putObject( charIDToTypeID( "T   " ), stringIDToTypeID('currentToolOptions'), toolDesc );
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );

But neither work.

Paul MR

Setting brush options

Post by Paul MR »

Thank you for that Mike, another question though.. How did you manage to get the second list of keys, you mentioned the brush was active? Is there a way to try and set these fields when the brush is in this state so the keys are available?

Mike Hale

Setting brush options

Post by Mike Hale »

The second set of keys are the descriptor keys of currentToolOptions when the brush tool is selected so all of those keys can be read with an executeActionGet. I just can't work out how to set them. It may not be possible and we will be forced to use tool presets.

Below is another variation that doesn't work.

Code: Select all    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putEnumerated( stringIDToTypeID('currentToolOptions'), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
    desc.putReference( charIDToTypeID( "null" ), ref );
   var desc1 = new ActionDescriptor();
      desc1.putInteger(stringIDToTypeID( 'opacity'), 50 );
    desc.putObject( charIDToTypeID( "T   " ), stringIDToTypeID('currentToolOptions'), desc1 );
   executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );

getInteger

Setting brush options

Post by getInteger »

I tried to get and set the angle of a brush, the angle is correctly seted but the selected brush is changed automatically to Soft Round 25 :s
Does anyone knows how to specify a brush ? I would like to keep the previously selected brush.

Code: Select all*function setBrushAngle(angle) {
   while(angle > 180) {
      angle = angle - 360
   }
   while(angle < -180) {
      angle = angle + 360
   }
    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.putUnitDouble( stringIDToTypeID( "angle" ), charIDToTypeID( "#Prc" ), angle );
    desc.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "Brsh" ), desc1 );
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
};

Mike Hale

Setting brush options

Post by Mike Hale »

If your brush is a sampled brush I don't know of any way to change any of the brush setting without Photoshop changing the brush to a computed brush.

getInteger

Setting brush options

Post by getInteger »

What do you mean ?
My brush is a custom one i made, i use a special shape and a special texture, can it be helpful ?

Mike Hale

Setting brush options

Post by Mike Hale »

That is a sampled brush. As far as I can tell you can't edit it with scripting.