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

How do I get tool properties?

Engaged ,
Jan 21, 2019 Jan 21, 2019

Copy link to clipboard

Copied

hello,as picture ,How do I get tool properties please?such as the Brush Tool   mode:Normal,opacity:100%,Flow:100%,smoothing:0%

QQ截图20190121184950.png

[Discussion successfully moved from Photoshop to Photoshop Scripting by moderator]

TOPICS
Actions and scripting

Views

1.4K

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 , Jan 22, 2019 Jan 22, 2019

var param = get_brush_param();

// examples

alert(param.opacity, "Opacity");

alert(param.diameter, "Diameter");

// show all (almost all) brush props

alert(obj_to_str(param), "Brush options");

function obj_to_str(obj){var str = ""; for (var p in obj) if(obj.hasOwnProperty(p))try{str+=p+"::"+obj

+"\n";}catch(e){};return str;}

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

function get_brush_param()

    {

    try {

        var r = new ActionReference();

        r.putProperty(stringIDToTypeID(

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 21, 2019 Jan 21, 2019

Copy link to clipboard

Copied

F5 toggles the Brush panels, or you can turn them on via the Window menu

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
Enthusiast ,
Jan 21, 2019 Jan 21, 2019

Copy link to clipboard

Copied

You can find and adjust the tool properties in the Options bar control panel. But I see in the picture that you already found it. So what exactly is your question?

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 ,
Jan 21, 2019 Jan 21, 2019

Copy link to clipboard

Copied

Thanks for your reply. i want to get the property of Tools via script such as the artlayer (app.activeDocument.activeArtlayer.fillOpacity)

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
Guest
Jan 21, 2019 Jan 21, 2019

Copy link to clipboard

Copied

Hi

Perhaps you should try here Photoshop Scripting

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
Enthusiast ,
Jan 21, 2019 Jan 21, 2019

Copy link to clipboard

Copied

Maybe you can find it in the Photoshop Scripting Guide: Adobe Photoshop CC Scripting Guide.pdf

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
Community Expert ,
Jan 21, 2019 Jan 21, 2019

Copy link to clipboard

Copied

Here you are looking for the current brush tool features.   This is not straight forward for there as so many brush types.   Brush features vary between brush type.  A round brush, a sample tipped brush,  special brush like a fan tip brush.   Different features are supported or not supported.   For example all brushes do not support Hardness/softness.

In the Photoshop Scripting forum there are many scripting sample that gets at some brush types current features.  I have not seem a generalized brush script that well retrieve the features of the current brush no matter what kind of brush is current. I also only hack at scripting I do not know JavaScript and Adobe DOM does not cover all of Photoshop feature.  Often Action Manager code must be user in a Photoshop scripts to do some things.  Here is a JavaScript function to set a round brush tip brush tip feature,  The function first uses Action Manager code to retrieve the current round tip brush's features in case a setting has not been pass to the function. The last thing the function  does is set the setting passed to the function by the coder.

function setBrushFeatures (Diameter,Hardness,Angle,Roundness,Spacing,Flipy,Flipx) {

    //A Brush tool must be the current tool

    if (!app.toolSupportsBrushes(app.currentTool)) selectBrush();  //CC 2014 test if the current tool is a brush type tool else select the brusg tool

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

    if (Diameter == undefined || Diameter == null) Diameter = brushDesc.getDouble(stringIDToTypeID('diameter'));

    if (Hardness == undefined || Hardness == null) Hardness = brushDesc.getDouble(stringIDToTypeID('hardness'));

    if (Angle == undefined || Angle == null ) Angle = brushDesc.getDouble(stringIDToTypeID('angle'));

    if (Roundness  == undefined || Roundness  == null) Roundness = brushDesc.getDouble(stringIDToTypeID('roundness'));

    if (Spacing == undefined || Spacing == null ) Spacing = brushDesc.getDouble(stringIDToTypeID('spacing')); 

    if (Flipy == undefined || Flipy == null ) Flipy = brushDesc.getBoolean(stringIDToTypeID('flipY')); 

    if ( Flipx == undefined || Flipx == null ) Flipx = brushDesc.getBoolean(stringIDToTypeID('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);

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

}

JJMack

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 ,
Jan 21, 2019 Jan 21, 2019

Copy link to clipboard

Copied

Thanks for your answer that It's just what I need, I need not only brush but all  properties of tools, in addition, I need to “get “”rather than “put”, it's a succuss cases that i try to get the diameter of brush,the script as follow:

     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   Diameter = brushDesc.getDouble(stringIDToTypeID('diameter'));

    alert(Diameter);

but i have a question that  i try to get property of Opacity( or Flow or Smoothing) is fail.how  do i get it ?

,,

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
Community Expert ,
Jan 21, 2019 Jan 21, 2019

Copy link to clipboard

Copied

You should be asking in the  in the Photoshop Scripting forum I only hack as Photoshop scripting.   Action Manager code is above my pay grade.   I can hack at the action manager code the scriptlisener plug-in records for me but that is all execution steps not get reference information. You need to know JavaScript well ( I do not)  and also know how to get Photoshop internal name descriptors id codes whatever.  I do not have that knowledge. The user that seems to have a good handle on things like that is r-bin he hangs out in the scripting forum and is usually very helpful.

JJMack

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 ,
Jan 21, 2019 Jan 21, 2019

Copy link to clipboard

Copied

thanks,I desperately need this knowledge of ActionManager

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
People's Champ ,
Jan 22, 2019 Jan 22, 2019

Copy link to clipboard

Copied

var param = get_brush_param();

// examples

alert(param.opacity, "Opacity");

alert(param.diameter, "Diameter");

// show all (almost all) brush props

alert(obj_to_str(param), "Brush options");

function obj_to_str(obj){var str = ""; for (var p in obj) if(obj.hasOwnProperty(p))try{str+=p+"::"+obj

+"\n";}catch(e){};return str;}

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

function get_brush_param()

    {

    try {

        var r = new ActionReference();

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

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

        var d = executeActionGet(r);

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

        var ret = new Object();

        try { var brush = options.getObjectValue(stringIDToTypeID("brush")); } catch(e) { alert("Current tool not brush!"); return ret; }

        for (var i = 0; i < options.count; i++)

            {

            var key = options.getKey(i);

            var type = options.getType(key);

            var val = undefined;

            switch (type)

                {

                case DescValueType.BOOLEANTYPE:    val = options.getBoolean(key); break;

                case DescValueType.DOUBLETYPE:     val = options.getDouble(key);  break; 

                case DescValueType.INTEGERTYPE:    val = options.getInteger(key); break;

                case DescValueType.ENUMERATEDTYPE: val = typeIDToStringID(options.getEnumerationValue(key)); break;

                case DescValueType.UNITDOUBLE:     val  = options.getUnitDoubleValue(key); break; // not quite right

                }

           

            if (val != undefined)

                {

                var name = typeIDToStringID(key);

                if (!name) name = typeIDToCharID(key);

                if (typeof(val) == "string")

                    eval("ret." + name +"='"+val+"'");

                else

                    eval("ret." + name +"="+val);

                }

            }

        for (var i = 0; i < brush.count; i++)

            {

            var key = brush.getKey(i);

            var type = brush.getType(key);

            var val = undefined;

            switch (type)

                {

                case DescValueType.BOOLEANTYPE:    val = brush.getBoolean(key); break;

                case DescValueType.DOUBLETYPE:     val = brush.getDouble(key);  break; 

                case DescValueType.INTEGERTYPE:    val = brush.getInteger(key); break;

                case DescValueType.ENUMERATEDTYPE: val = typeIDToStringID(brush.getEnumerationValue(key)); break;

                case DescValueType.UNITDOUBLE:     val = brush.getUnitDoubleValue(key); break; // not quite right

                }

           

            if (val != undefined)

                {

                var name = typeIDToStringID(key);

                if (!name) name = typeIDToCharID(key);

                if (typeof(val) == "string")

                    eval("ret." + name +"='"+val+"'");

                else

                    eval("ret." + name +"="+val);

                }

            }               

        return ret;

        }

    catch (e) { alert(e); }

    }

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 ,
Jan 22, 2019 Jan 22, 2019

Copy link to clipboard

Copied

you are powerful !  where  is the  datasheet about the properties ? i don't know which words can be used for stringIDToTypeID?

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
People's Champ ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

LATEST

What will the knowledge of strinIDs give you? You still need to know how to use these IDs. By and large, these IDs should be described in the SDK documentation, or in the documentation to, for example, a plugin that supports recording in Actions.

In the above function, StringIDs are obtained using the typeIDToStringID() function.
I note that in addition to the name (or ID) of the parameter, you still need to know its type in order to correctly read the data from the descriptor.

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