2 Replies Latest reply on Oct 16, 2015 1:39 PM by oliverIntergrafika

    How can I color a layer without selecting it?

    oliverIntergrafika Level 2

      I have this little function which is working fine except the slow layer selection. Could someone show me the way how to color a layer without actually go there and higlight it with selection? As You can see the line 13. is the selection. Would be nice if We could get rid of it somehow.

       

      colorLayer = function( layerIndex, colorNAME )
      {
          var color = { "GREEN": "Grn ", "RED": "Rd  ", "BLUE": "Bl  ", "ORANGE": "Orng", "YELLOW": "Ylw ", "VIOLET": "Vlt ", "GRAY": "Gry ", "NONE": "None" }[ colorNAME ];
          var desc1 = new ActionDescriptor();
          var ref1 = new ActionReference();
          ref1.putIndex( charIDToTypeID( "Lyr " ), layerIndex );
          desc1.putReference( charIDToTypeID( "null" ), ref1 );
          var desc2 = new ActionDescriptor();
          desc2.putEnumerated( charIDToTypeID( "Clr " ), charIDToTypeID( "Clr " ), charIDToTypeID( color ) );
          desc1.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "Lyr " ), desc2 );
          executeAction( charIDToTypeID( 'slct' ), desc1, DialogModes.NO );
          executeAction( charIDToTypeID( "setd" ), desc1, DialogModes.NO );
      }
      
      

       

      Is there a 'trgt' or something instead of 'slct'? Where can I learn about these IDs?

        • 1. Re: How can I color a layer without selecting it?
          Mikaeru69 Level 3

          This should work; it only uses internal string IDs. Note that yellow is "yellowColor" instead...

           

          function colorLayer (layerIndex, color)
          {  
              var desc1 = new ActionDescriptor();  
              var ref1 = new ActionReference();  
              ref1.putIndex (stringIDToTypeID ("layer"), layerIndex);  
              desc1.putReference (stringIDToTypeID ("target"), ref1);  
              var desc2 = new ActionDescriptor();  
              desc2.putEnumerated (stringIDToTypeID ("color"), stringIDToTypeID ("color"), stringIDToTypeID (color));  
              desc1.putObject (stringIDToTypeID ("to"), stringIDToTypeID ("layer"), desc2);
              executeAction (stringIDToTypeID ("set"), desc1, DialogModes.NO);
          }
          colorLayer (1, "red"); // color: "none", "red", "orange", "yellowColor", "green", "blue", "violet", "gray"
          

           

          HTH,

           

            --Mikaeru

          • 2. Re: How can I color a layer without selecting it?
            oliverIntergrafika Level 2

            Thank You for the answer Mikaeru69!

             

            Interresting to see the using of String IDs as a paralell universe.

             

            But the script is coloring the actual (selected) layer. It ignores the layerIndex somehow.