欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【photoshop Action Manager】动作管理器 - 获取工具属性

程序员文章站 2022-05-19 15:56:15
...

1.比如获取当前笔刷

var param = get_brush_param();  
  
//alert(param.opacity, "Opacity");  
//alert(param.diameter, "Diameter");  
  
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[p]+"\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(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));
                    if (!val)  
                        val = typeIDToCharID(options.getEnumerationValue(key));  
                    break;  
                case DescValueType.UNITDOUBLE:     val  = options.getUnitDoubleValue(key); break; // not quite right  
                case DescValueType.OBJECTTYPE:		 val = options.getObjectValue(key); break; 
             //   case DescValueType.REFERENCETYPE: 	 val = getReference(options.getReference(key)); break;   
                default: 				val =  options.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);   
                }  
            }  
  
        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(options.getEnumerationValue(key));
                if (!val)  
                    val = typeIDToCharID(options.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 + "/tool_brush.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();  
};  

 

【photoshop Action Manager】动作管理器 - 获取工具属性