Показать сообщение отдельно
  #7 (permalink)  
Старый 07.04.2023, 08:26
Новичок на форуме
Отправить личное сообщение для raaaatata Посмотреть профиль Найти все сообщения от raaaatata
 
Регистрация: 06.04.2023
Сообщений: 6

ваш скрипт не работает
error 60
Line 16

вот что получилось у меня, но сейчас скрипт работает не до конца правильно, подкрепил скрин

// select layers the name of which ends in "_xx_xx";
if (app.documents.length > 0) {
// search layers with regexp;
var theLayers = collectLayersByNames([/(mask|back|step)_\d{1,2}_\d{1,2}$/], 2);
// process layers;
    if (theLayers.length > 0) {
        for (var d = 0; d < theLayers.length; d++) {
            selectLayerByID(theLayers[d][0][2], false);
            for (var e = 1; e < theLayers[d].length; e++) {
                selectLayerByID(theLayers[d][e][2], true)
                };
// group the active layer;
           groupSelectedLayers("[slot] step" + String(theLayers[d][0][0].match(/_\d{1,2}_\d{1,2}$/)).replace(/_/g, "-"));
            };
        } else {alert ("no such layer")}
    };
////////////////////////////////////
////// collect layers and/or groups with certain name, 0 layers, 1 groups, 2 both //////
function collectLayersByNames (theNames, layersOrGroups) {
// get number of layers;
    var ref = new ActionReference();
    ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
    ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
    var applicationDesc = executeActionGet(ref);
    var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
    var theLayers = new Array;
    for (var m = 0; m <= theNumber; m++) {
    try {
    var ref = new ActionReference();
    ref.putIndex( charIDToTypeID( "Lyr " ), m);
    var layerDesc = executeActionGet(ref);
    var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
    var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if group collect values;
    var theCheck = false;
        switch (Number(layersOrGroups)) {
            case 0:
                if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart") {theCheck = true}
            break;
            case 1:
                if (layerSet == "layerSectionStart") {theCheck = true}
            break;
            default:
                if (layerSet != "layerSectionEnd") {theCheck = true}
            break;
        };
    if (theCheck == true && isBackground != true) {
    var theName = layerDesc.getString(stringIDToTypeID('name'));
    var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
    var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
// check name;
    for (var x = 0; x < theNames.length; x++) {
        var theNumbers = theName.match(theNames[x]);
        if (theNumbers != null) {
            var theCheck = false;
            for (var y = 0; y < theLayers.length; y++) {
                if (theNumbers == String(theLayers[y][0][0].match(theNames[x]))) {
                    theLayers[y].push([theName, theIndex, theID]);
                    theCheck = true;
                };
            };
            if (theCheck ==  false) {
                theLayers.push([[theName, theIndex, theID]])
            }
            }
        }
    };
    }
    catch (e) {};
    };
    return theLayers
    };
////// based on code by mike hale and paul riggott //////
function selectLayerByID(theID,add){ 
    add = undefined ? add = false:add 
    var ref = new ActionReference();
        ref.putIdentifier(charIDToTypeID("Lyr "), theID);
        var desc = new ActionDescriptor();
        desc.putReference(charIDToTypeID("null"), ref );
            if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); 
            desc.putBoolean( charIDToTypeID( "MkVs" ), false ); 
        try{
        executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
    }catch(e){
    alert(e.message); 
    }
    };
////// group //////
function groupSelectedLayers (theName) {
    var desc159 = new ActionDescriptor(); 
    var ref114 = new ActionReference(); 
    var idlayer = stringIDToTypeID( "layer" );
    var idordinal = stringIDToTypeID( "ordinal" );
    var idtargetEnum = stringIDToTypeID( "targetEnum" );
    var idnull = stringIDToTypeID( "null" );
    var idname = stringIDToTypeID( "name" );
    ref114.putEnumerated(idlayer, idordinal, idtargetEnum); 
    desc159.putReference(idnull, ref114 );
    desc159.putString(idname, "aaa" );
    executeAction( stringIDToTypeID( "groupLayersEvent" ), desc159, DialogModes.NO );
    var desc63 = new ActionDescriptor();
    var ref37 = new ActionReference();
    ref37.putEnumerated( idlayer, idordinal, idtargetEnum );
    desc63.putReference( idnull, ref37 );
    var desc64 = new ActionDescriptor();
    desc64.putString(idname, theName);
    desc63.putObject(stringIDToTypeID( "to" ), idlayer, desc64);
    executeAction(stringIDToTypeID( "set" ), desc63, DialogModes.NO)
};
Изображения:
Тип файла: jpg 2023-04-07_00-04-42.jpg (12.3 Кб, 1 просмотров)
Ответить с цитированием