如何获取与图层组名称相关的图层数据?

时间:2019-08-09 07:45:39

标签: javascript photoshop photoshop-script

我正在制作一个Photoshop脚本,该脚本使用“斜角”和“浮雕”效果获取每一层,然后执行一些操作。我已经设置了此功能,以便获取图层数据...

function getLayersData()  
{  
    var lyrs = [];  
    var layers = 1;  
    while (true)  
    {  
        ref = new ActionReference();  
        ref.putIndex(charIDToTypeID('Lyr '), layers);  

        try  
        {  
            var d1 = executeActionGet(ref);  
            var d2 = executeActionGet(ref);  
            var d3 = executeActionGet(ref);  
            var d4 = executeActionGet(ref);  
        }  
            catch (err)  
        {  
            break;  
        };  

        var c2t = function (s){return app.charIDToTypeID(s);};  
        var s2t = function (s){return app.stringIDToTypeID(s);};  
        var lyr = {};  

        lyr.type = d1.getInteger(s2t("layerKind"));  
        lyr.name = d1.getString(c2t("Nm  "));  
        lyr.id = d1.getInteger(s2t("layerID"));  

        if (checkbox1.value == true)  
        {  
            ref.putEnumerated( c2t("Lyr "), c2t("Ordn"), c2t("Trgt") );  
            if (d1.hasKey(s2t('layerEffects')))  
            {  
                d1 = d1.getObjectValue(s2t('layerEffects'));  
                lyr.scale = d1.getUnitDoubleValue(s2t('scale'));  

                if (d1.hasKey(s2t('bevelEmboss')))  
                {  
                    d1 = d1.getObjectValue(s2t('bevelEmboss'));  
                        lyr.enabled = d1.getBoolean(s2t('enabled'));  
                        lyr.present = d1.getBoolean(s2t('present'));  
                        lyr.showInDialog = d1.getBoolean(s2t('showInDialog'));  
                        lyr.highlightMode = typeIDToStringID(d1.getEnumerationValue(s2t('highlightMode')));  
                    d2 = d1.getObjectValue(s2t('highlightColor'));  
                        lyr.red_hlc = d2.getDouble(s2t('red'));  
                        lyr.grn_hlc = d2.getDouble(s2t('green'));  
                        lyr.blue_hlc = d2.getDouble(s2t('blue'));  
                        lyr.highlightOpacity = d1.getUnitDoubleValue(s2t('highlightOpacity'));  
                        lyr.shadowMode = typeIDToStringID(d1.getEnumerationValue(s2t('shadowMode')))  
                    d3 = d1.getObjectValue(s2t('shadowColor'));  
                        lyr.red_sdc = d3.getDouble(s2t('red'));  
                        lyr.grn_sdc = d3.getDouble(s2t('green'));  
                        lyr.blue_sdc = d3.getDouble(s2t('blue'));  
                        lyr.shadowOpacity = d1.getUnitDoubleValue(s2t('shadowOpacity'));  
                        lyr.bevelTechnique = typeIDToStringID(d1.getEnumerationValue(s2t('bevelTechnique')));  
                        lyr.bevelStyle = typeIDToStringID(d1.getEnumerationValue(s2t('bevelStyle')));  
                        lyr.useGlobalAngle = d1.getBoolean(s2t('useGlobalAngle'));  
                        lyr.localLightingAngle = d1.getUnitDoubleValue(s2t('localLightingAngle'));  
                        lyr.localLightingAltitude = d1.getUnitDoubleValue(s2t('localLightingAltitude'));  
                        lyr.strengthRatio = d1.getUnitDoubleValue(s2t('strengthRatio'));  
                        lyr.blur = d1.getUnitDoubleValue(s2t('blur'));  
                        lyr.bevelDirection = typeIDToStringID(d1.getEnumerationValue(s2t('bevelDirection')));  
                    d4 = d1.getObjectValue(c2t('TrnS'));  
                        lyr.TrnSName = d4.getString(s2t('name'));  
                        lyr.antialiasGloss = d1.getBoolean(s2t('antialiasGloss'));  
                        lyr.softness = d1.getUnitDoubleValue(s2t('softness'));  
                        lyr.useShape = d1.getBoolean(s2t('useShape'));  
                        lyr.useTexture = d1.getBoolean(s2t('useTexture'));  
                    lyrs.push(lyr);  
                };  
            };  
        }  
        else  
        {  
            lyrs.push(lyr);  
        };  
        layers++;  
    };      
    return lyrs;  
}; 

...然后使用此功能,以便将这些图层列出到DropDownList中。

function onChangeDropdownlist1()  
{  
    dropdownlist2.removeAll();  
    var layerData = getLayersData();  
    var layerNames=[];  
    for(var a in layerData){if(layerData[a].type == dropdownlist1.selection.index){layerNames.push(layerData[a].name);};};  
    if (checkbox2.value == true){layerNames = UniqueSortedList(layerNames);};  
    for(var z in layerNames){dropdownlist2.add("item", layerNames[z]);};  
    dropdownlist2.selection = 0;  
    if (dropdownlist2.selection == null){edittext1.text = "";};  
}; 

我现在想做的是增加获得此列表的功能,但要与组名有关! 知道我该怎么做吗?

0 个答案:

没有答案