Skip to main content
Naoki-Hada
Known Participant
November 3, 2017
Answered

[Q] Brush's spacing setting for get/set or ignore.

  • November 3, 2017
  • 2 replies
  • 2195 views

Hi all,

Is there solution for Brush's spacing (check box) setting avoid reset when script set brush's hardness.

# I mean I just want to change hardness. But I'm digging hole deeper and deeper.

When I tried to record to change Brush's Hardness change by ScriptListner, it seems not recording.

Brush size was recorded fine. The code was re-usable.

I found JJMack​'s code at Is it possible to script brush opacity?

and testing.

But if Spacing checkbox was OFF, it change to checkbox ON and 25% as default setting.

Is there way to get and set checkbox of Spacing?

Or just change Hardness without spacing reset?

Following is test code.

If Spacing checkbox is ON, it works as expected as no change.

If Spacing checkbox is OFF, Spacing setting gets reset.

Test code

var _r1 = getBrushFeatures ();

$.writeln("_r1 = ", _r1);

setBrushFeatures (_r1[0],_r1[1],_r1[2],_r1[3],_r1[4],_r1[5],_r1[6]); // test: set same value

//setBrushFeatures (1,2,3,4,5,true,false); // test: overwrite

var _r2 = getBrushFeatures ();

$.writeln("_r2 = ", _r2);

$.writeln('debugger break');

function getBrushFeatures (){ 

  //A Brush tool must be the current tool 

    if (!app.toolSupportsBrushes(app.currentTool)) selectBrush();  //CC 2014 

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

    var currDiameter = brushDesc.getDouble(stringIDToTypeID('diameter'));   

    var currHardness = brushDesc.getDouble(stringIDToTypeID('hardness'));   

    var currAngle = brushDesc.getDouble(stringIDToTypeID('angle'));   

    var currRoundness = brushDesc.getDouble(stringIDToTypeID('roundness'));   

    var currSpacing = brushDesc.getDouble(stringIDToTypeID('spacing'));   

    var currFlipy = brushDesc.getBoolean(stringIDToTypeID('flipY'));   

    var currFlipx = brushDesc.getBoolean(stringIDToTypeID('flipX')); 

    var currentFeatures = new Array( currDiameter, currHardness, currAngle, currRoundness, currSpacing, currFlipy, currFlipx ); 

    return currentFeatures 

 

function setBrushFeatures (Diameter,Hardness,Angle,Roundness,Spacing,Flipy,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);   

    // Commeting out next line will reset: Checkbox ON 25% as default

    desc1.putUnitDouble( stringIDToTypeID('spacing'), charIDToTypeID('#Prc'), Spacing); 

    desc1.putBoolean(stringIDToTypeID('flipY'), Flipy);   

    desc1.putBoolean(stringIDToTypeID('flipX'), Flipx);   

    desc.putObject( stringIDToTypeID('to'), charIDToTypeID( "Brsh" ), desc1 );   

    executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );   

Thank you,

Naoki

This topic has been closed for replies.
Correct answer r-bin

Here is the function you need )

// set only hardnesss 55

set_brush(undefined, 55)

///////////////////////////////////////////////////////////////////////////////////////////////////

function set_brush(d, h, s)

    {

    try {

        var r = new ActionReference();

        r.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "tool" ) );

        r.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

        var ret = executeActionGet(r);

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

        var desc1 = ret.getObjectValue(stringIDToTypeID("brush"));             

        var desc = new ActionDescriptor();

        var ref = new ActionReference();

        ref.putEnumerated( charIDToTypeID( "Brsh" ), charIDToTypeID( "Ordn"), charIDToTypeID( "Trgt" ) );

  

        desc.putReference( charIDToTypeID( "null" ), ref );

        if (d != undefined) desc1.putUnitDouble( charIDToTypeID( "Dmtr" ), charIDToTypeID( "#Pxl" ), d );

        if (h != undefined) desc1.putUnitDouble( charIDToTypeID( "Hrdn" ), charIDToTypeID( "#Prc" ), h );

        if (s != undefined) desc1.putUnitDouble( charIDToTypeID( "Spcn" ), charIDToTypeID( "#Prc" ), s );

        desc.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "Brsh" ), desc1 );

        executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );

        }

    catch (e) { alert(e); throw(e); }

    }

2 replies

r-binCorrect answer
Legend
November 4, 2017

Here is the function you need )

// set only hardnesss 55

set_brush(undefined, 55)

///////////////////////////////////////////////////////////////////////////////////////////////////

function set_brush(d, h, s)

    {

    try {

        var r = new ActionReference();

        r.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "tool" ) );

        r.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

        var ret = executeActionGet(r);

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

        var desc1 = ret.getObjectValue(stringIDToTypeID("brush"));             

        var desc = new ActionDescriptor();

        var ref = new ActionReference();

        ref.putEnumerated( charIDToTypeID( "Brsh" ), charIDToTypeID( "Ordn"), charIDToTypeID( "Trgt" ) );

  

        desc.putReference( charIDToTypeID( "null" ), ref );

        if (d != undefined) desc1.putUnitDouble( charIDToTypeID( "Dmtr" ), charIDToTypeID( "#Pxl" ), d );

        if (h != undefined) desc1.putUnitDouble( charIDToTypeID( "Hrdn" ), charIDToTypeID( "#Prc" ), h );

        if (s != undefined) desc1.putUnitDouble( charIDToTypeID( "Spcn" ), charIDToTypeID( "#Prc" ), s );

        desc.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "Brsh" ), desc1 );

        executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );

        }

    catch (e) { alert(e); throw(e); }

    }

Naoki-Hada
Known Participant
November 4, 2017

r-bin

Thank you very much for the code and extra time to verify.

I also verified working as expected.

Thank you,

Naoki

Legend
November 3, 2017

////////////////////////////////////////////////////////////////////////////////////////////

function get_brush_space_checkbox()

    {

    try

        {

        var r = new ActionReference();

        r.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "tool" ) );

        r.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

        var ret = executeActionGet(r);

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

        ret = ret.getObjectValue(stringIDToTypeID("brush"));           

        ret = ret.getBoolean(stringIDToTypeID("interfaceIconFrameDimmed"));           

        return ret;

        }

    catch (e) { alert(e); }

    }

///////////////////////////////////////////////////////////////////////////////////////////////////

function set_brush_space_checkbox(val)

    {

    try {

        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.putBoolean( stringIDToTypeID("interfaceIconFrameDimmed"), val);

        desc.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "Brsh" ), desc1 );

        executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );

        ref = null;

        desc = null;

        desc1 = null;

        }

    catch (e) { alert(e); throw(e); }

    }

///////////

upd.

without a string

r.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "tool" ) );

your code will be very slow because executeActionGet will try to dispose of all the "capp" properties such as systeminfoj.fontlist, etc.

Naoki-Hada
Known Participant
November 4, 2017

r-bin

Thank you very much for the code.

As I tested, get part is working as expected.

Set part seems has problem. It set proper value to Spacing checkbox.

But Size and Hardness seems get reset to default.

Size=25px, Hardness=0%.

It might be depends on brush type.

But I was looking for the other code you posted.

So I go with the code.

And also thank you for the tips for code performance.

It is also valuable to avoid future pithole.

Thank you,

Naoki