1 Reply Latest reply on Jan 21, 2014 2:35 AM by c.pfaffenbichler
      • 1. Re: Search layers for a layer called XXX and resize to 200%
        c.pfaffenbichler Level 9

        This might work.

        // 2014, use it at your own risk;

        #target photoshop

        if (app.documents.length > 0) {

        var myDocument = app.activeDocument;

        main ();

        };

        ////////////////////////////////////

        function main () {

        // get number of layers;

        var ref = new ActionReference();

        ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

        var applicationDesc = executeActionGet(ref);

        var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));

        // check layers;

        for (var m = 0; m <= theNumber; m++) {

        try {

        var ref = new ActionReference();

        //ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

        ref.putIndex( charIDToTypeID( "Lyr " ), m);

        var layerDesc = executeActionGet(ref);

        var layerSet = layerDesc.getEnumerationValue(stringIDToTypeID("layerSection"));

        // if not layer group check name;

        if (layerSet != 2652 && layerSet != 2638) {

        var theName = layerDesc.getString(stringIDToTypeID('name'));

        if (theName == "XXX") {

        selectLayerByIndex(m,false);

        app.activeDocument.activeLayer.resize(200, 200, AnchorPosition.MIDDLECENTER)

        }

        };

        }

        catch (e) {};

        };

        };

        // by mike hale, via paul riggott;

        // http://forums.adobe.com/message/1944754#1944754

        function selectLayerByIndex(index,add){

        add = undefined ? add = false:add

        var ref = new ActionReference();

            ref.putIndex(charIDToTypeID("Lyr "), index);

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

        }

        };