2 Replies Latest reply on Jul 7, 2014 4:55 AM by Mii-Zk5I1Q

    How do I get the Photoshop layer tags in JavaScript?

    Mii-Zk5I1Q

      I asked this question at graphic design stack exchange but they pointed me here:

       

      http://graphicdesign.stackexchange.com/questions/35374/how-do-i-get-the-photoshop-layer-ta gs-in-javascript?noredirect=1#comment48962_35374

       

      I want to do actions based on the tagged layer color (these thing 1) in Photoshop. I can't find a property inside the JavaScript documentation or the ExtendScript Toolkit that might contain the value.

      I'd prefer not to abuse the name for that, the layer tags look like a very clean solution to my problem. If only I could fetch them.

       

      Any Ideas?

       

      Kind Regards,

      Mii

        • 1. Re: How do I get the Photoshop layer tags in JavaScript?
          cbuliarca Level 3

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