如何使用Photoshop的javascript识别PSD的内部/外部/中心笔画

时间:2019-06-20 13:22:05

标签: javascript photoshop photoshop-script

我想识别和确定PSD层笔画的内部/外部/中心的像素大小 在这里,我有一些代码可以识别图层的笔触,但是我找不到图层上的笔触类型

 function hasLayerFX(){  
 var ref = new ActionReference();  
 ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );   
 return  executeActionGet(ref).hasKey(stringIDToTypeID('layerEffects'));  
 }; 


var doc = app.activeDocument;
var layers = app.activeDocument.layers;
for (var x = 0; x < layers.length; x++) {
    doc.activeLayer = doc.layers[x];
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"),  charIDToTypeID("Trgt"));
    var desc = executeActionGet(ref);
var results = hasLayerFX();
if(results == true){
    var stork =     executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).hasKey(stringIDToTypeID('frameFX')); 
    if(stork == true){

    alert("This layer contains stork");
    }
}
}

1 个答案:

答案 0 :(得分:0)

frameFX是一个对象描述符,就像layerEffects一样。因此,当您确定该图层具有笔触时(使用hasKey),您只需从图层描述符中获取这些值即可。要知道要寻找什么值,请使用Jaroslav Bereza的Action Manager Humanizer

var doc = app.activeDocument,
    layers = doc.layers;

for (var x = 0; x < layers.length; x++)
{
    doc.activeLayer = doc.layers[x];
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    var desc = executeActionGet(ref);

    if (hasStroke(desc))
    {
        var strokeValues = getStrokeValues(desc);
        alert("Layer " + doc.layers[x].name + " has a " + strokeValues.type + " stroke with " + strokeValues.value + "px size");
    }
}

function hasStroke(d)
{
    if (!d.hasKey(stringIDToTypeID('layerEffects'))) return false
    if (!d.getObjectValue(stringIDToTypeID('layerEffects')).hasKey(stringIDToTypeID('frameFX'))) return false
    return true
}; // end of hasStroke()

function getStrokeValues(d) {
    var temp = d.getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('frameFX'));
    // possible values of the 'style' are insetFrame, centeredFrame and outsetFrame
    return {
        type: typeIDToStringID(temp.getEnumerationValue(stringIDToTypeID("style"))),
        value: temp.getInteger(stringIDToTypeID("size"))
    }
}; // end of getStrokeValues()