Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 92406

Re: How do I get the Photoshop layer tags in JavaScript?

$
0
0

Hi, these functions will select all your layers with the specified color:

use the command: selectAllByColor("red");

function getIDXwithsameColor(TheColor){// search and return a list of indexes for the layers with the specified color

    var ref = new ActionReference();

    var toRet = [];

    try{activeDocument.backgroundLayer;var a=0 }catch(e){ var a = 1; };

    while(true){

      ref = new ActionReference();

      ref.putIndex( charIDToTypeID( 'Lyr ' ), a );

      try{var desc = executeActionGet(ref);}catch(err){break;}

        var cl = desc.getEnumerationValue(charIDToTypeID("Clr "));

        cl = typeIDToStringID(cl);

        var ls = desc.getEnumerationValue(stringIDToTypeID("layerSection"));

        ls = typeIDToStringID(ls);

        if(ls != 'layerSectionEnd'){

          if(cl == TheColor){

            toRet.push(a);

          }

        }

      a++;

    }

    return toRet;

}

function multiSelectByIDX(idx) {// selection function

  if( idx.constructor != Array ) idx = [ idx ];

    var layers = new Array();

    var desc = new ActionDescriptor();

    var ref = new ActionReference();

    for (var i = 0; i < idx.length; i++) {

          layers[i] = charIDToTypeID( "Lyr " );

          ref.putIndex(layers[i], idx[i]);

    }

    desc.putReference( charIDToTypeID( "null" ), ref );

    executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );

}

function selectAllByColor(TheColor){// main function

  theSameClIDX = getIDXwithsameColor(TheColor);

  multiSelectByIDX(theSameClIDX);

}

//...example::

 

 

// selectAllByColor("none");

//selectAllByColor("red");

// selectAllByColor("orange");

// selectAllByColor("yellowColor");

// selectAllByColor("grain");

// selectAllByColor("blue");

// selectAllByColor("violet");

// selectAllByColor("gray");


Viewing all articles
Browse latest Browse all 92406

Trending Articles