Skip to main content
greless
Inspiring
February 19, 2019
Question

how to get brush name?

  • February 19, 2019
  • 2 replies
  • 1389 views

i had been getting the name of  part of the brush.but some of brush name unable to get.the code as fallow:

var param = get_brush_param(); 

// examples 

// show all (almost all) brush props 

 

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

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

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

      logInfo( str);

    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(charIDToTypeID("CrpO")); } catch(e) { alert("Current tool not brush!"); return ret; }  

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

 

  // alert( options.count);

  //  alert( brush.count);

     

 

        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 

                  case DescValueType.STRINGTYPE: val = brush.getString(key); break;  

              //  case DescValueType.REFERENCETYPE: val = getReference(brush.getReference(key)); break;  

                default: val =  brush.getType(key).toString();

                } 

             

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

    } 

function logInfo(Txt){ 

var file = new File(Folder.desktop + "/too_brush1.txt"); 

file.open("w", "TEXT", "????"); 

file.seek(0,2); 

$.os.search(/windows/i)  != -1 ? file.lineFeed = 'windows'  : file.lineFeed = 'macintosh'; 

file.writeln(Txt); 

file.close(); 

}; 

this is successful.

this is fail,i can't get the name.

This topic has been closed for replies.

2 replies

greless
grelessAuthor
Inspiring
February 19, 2019
Legend
February 19, 2019

It turns out that not all brushes have a property "name".

I do not know how to solve this problem. Maybe later I'll see what can be done.

In this thread Select/refer to brushes by name within brush sets by name

there is an attempt to find out the name of the brush.

See functions alert_curr_brush() and alert_curr_brush_v2().

But for you, most likely, it will not work.

greless
grelessAuthor
Inspiring
February 19, 2019

Thank you so much in advance and have a nice day.

is this a method that Getting the current preset brushes?

https://forums.adobe.com/message/10046190#10046190

JJMack
Community Expert
Community Expert
February 19, 2019

There are different types of Brushes your code seem to handle normal brushed with tound tips.  There are also sample tipped brushes, Mixer Brushes and special bush types.  In other words you code does not have support  for all posible Photosop brush types. There are also Many bursh type tools in Photoshop.

Different brush type have different attributes

JJMack
greless
grelessAuthor
Inspiring
February 19, 2019

each preset brushes has a name,so  could we get the name?