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

Update Brush Angle and Roundness for Sampled Brush

New Here ,
Jun 26, 2019 Jun 26, 2019

Copy link to clipboard

Copied

Hello all!

How can you change the angle and roundness of a sampledBrush?

So far it looks like you can only change these properties for the computedBrush.

JSON structure of brush extracted from currentToolOptions. As you can see, the sampled brush name and guid are stored in here.

{

   "_obj":"sampledBrush",

   "angle":{

      "_unit":"angleUnit",

      "_value":0.0

   },

   "diameter":{

      "_unit":"pixelsUnit",

      "_value":112.0

   },

   "flipX":false,

   "flipY":false,

   "interfaceIconFrameDimmed":true,

   "name":"Round Sketch Ballpoint Pen",

   "roundness":{

      "_unit":"percentUnit",

      "_value":100.0

   },

   "sampledData":"cabec8bc-a3b8-117a-8c68-a08beca1d52a",

   "spacing":{

      "_unit":"percentUnit",

      "_value":4.0

   }

}

This script will change my current selection to a computedBrush, even though I set properties for the currently selected sampled brush:

function GetBrushAMObject()

{

    var appAR = new ActionReference()

    appAR.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") )

    var app = executeActionGet(appAR)

    var brush = app.getObjectValue(stringIDToTypeID('currentToolOptions')).getObjectValue(stringIDToTypeID('brush'))

    return brush

}

function SetBrushAngleAndRoundness(Angle, Roundness)

{

    var brush = GetBrushAMObject()

    var paramsAD = new ActionDescriptor()

    paramsAD.putDouble(stringIDToTypeID('angle'), Angle)

    paramsAD.putDouble(stringIDToTypeID('roundness'), Roundness)

 

    var brushAD = new ActionDescriptor()

    var brushAR = new ActionReference()

    brushAR.putEnumerated( charIDToTypeID( "Brsh" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) )

    brushAD.putReference( charIDToTypeID( "null" ), brushAR ); 

    if( brush.hasKey(stringIDToTypeID('sampledData')))

    {

        var SampleIntr = brush.getBoolean(stringIDToTypeID('interfaceIconFrameDimmed'))

        var SampleData = brush.getString(stringIDToTypeID('sampledData'))

        var Name = brush.getString(stringIDToTypeID('name'))

        $.writeln('Brush interfaceIconFrameDimmed: ' + SampleIntr)

        $.writeln('Brush sampledData: ' + SampleData)

        $.writeln('Brush name: ' + Name)

        paramsAD.putString(stringIDToTypeID('sampledData'), SampleData)

        paramsAD.putString(stringIDToTypeID('name'), Name)

        paramsAD.putBoolean(charIDToTypeID('Intr'), SampleIntr)

    }

    brushAD.putObject( stringIDToTypeID('to'), stringIDToTypeID("sampledBrush"), paramsAD )

    executeAction( charIDToTypeID( "setd" ), brushAD, DialogModes.NO )

}

SetBrushAngleAndRoundness(-60, 70)

What I wanted:

WhatIWanted.PNG

What I got:

WhatIGot.PNG

Changing any brush settings will change the brush to a computed brush. The properites sampledData and name get ignored. This looks like a bug to me.

TOPICS
Actions and scripting

Views

459

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

correct answers 1 Correct answer

People's Champ , Jun 28, 2019 Jun 28, 2019

function SetBrushAngleAndRoundness(Angle, Roundness) 

var r = new ActionReference();

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));

r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var ret = executeActionGet(r);

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

var tool = ret.getEnumerationType(stringIDToTypeID("tool"));

var brush = options.getObjectValue(stringIDToTypeID("brush"

...

Votes

Translate

Translate
Adobe
People's Champ ,
Jun 28, 2019 Jun 28, 2019

Copy link to clipboard

Copied

function SetBrushAngleAndRoundness(Angle, Roundness) 

var r = new ActionReference();

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));

r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var ret = executeActionGet(r);

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

var tool = ret.getEnumerationType(stringIDToTypeID("tool"));

var brush = options.getObjectValue(stringIDToTypeID("brush"));          

brush.putDouble(stringIDToTypeID("angle"), Angle) 

brush.putDouble(stringIDToTypeID("roundness"), Roundness) 

options.putObject(stringIDToTypeID("brush"), stringIDToTypeID("sampledBrush"), brush);

var r = new ActionReference();

r.putClass(tool);

var d = new ActionDescriptor();

d.putReference(stringIDToTypeID("null"), r);

d.putObject(stringIDToTypeID("to"), stringIDToTypeID("null"), options);

executeAction(stringIDToTypeID("set"), d, DialogModes.NO);

}

 

SetBrushAngleAndRoundness(-60, 70)

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
LEGEND ,
Dec 28, 2020 Dec 28, 2020

Copy link to clipboard

Copied

LATEST

Can you or anyone explain what is difference between using:

 

options.putObject(stringIDToTypeID("brush"), stringIDToTypeID("sampledBrush"), brush);

 

and:

 

options.putObject(stringIDToTypeID("brush"), stringIDToTypeID("null"), brush);

 

and what that 'sampledBrush' is refered to?

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