4 Replies Latest reply on Mar 18, 2016 9:06 AM by tpk1982

    Layer name need to include

    tpk1982 Level 4

      Hi,

       

      I am trying to find the magenta color applied objects. The below coding working fine. But i need to include the error object layer name in the alert.

       

      var pageLen = app.activeDocument.pages.length 
      var mag=0
      for(i=0;i<pageLen;i++)
      {
              var pageItemLen = app.activeDocument.pages.item(i).pageItems.length 
              for(j=0;j<pageItemLen;j++)
              { 
                  color = 0; scolor =0
                  if(app.activeDocument.pages.item(i).pageItems.item(j).fillColor.name != "None")
                      color = app.activeDocument.pages.item(i).pageItems.item(j).fillColor.colorValue
                  if(app.activeDocument.pages.item(i).pageItems.item(j).strokeColor.name != "None")
                      scolor = app.activeDocument.pages.item(i).pageItems.item(j).strokeColor.colorValue
                  if(color == "0,100,0,0" || scolor == "0,100,0,0")
                        mag=1
                 }
          }
      
      
      if(mag==1)
      {
                alert("ERROR: Some Page ojects contain Magenta color fill/stroke")
          }
                      else{
                       alert("Page ojects not contain Magenta color fill/stroke")
      }
      

       

       

      I am little confused how to add it. Some one please help me?

       

      Regards,

      Karthi

        • 1. Re: Layer name need to include
          Loic.Aigon Adobe Community Professional

          Page items have an itemLayer property that will return the layer object. From that you can grab the layer name:

           

          app.activeDocument.pages.item(i).pageItems.item(j).itemLayer.name 
          

           

          HTH

           

          Loic

          ozalto.com

          • 2. Re: Layer name need to include
            tpk1982 Level 4

            Hi Loic,

             

            Thanks for your reply. I had magenta colored object in 2 layers and tested. But it shows only one layer name. May i know where i missed?

             

            var pageLen = app.activeDocument.pages.length 
            var mag=0 
            for(i=0;i<pageLen;i++) 
            { 
                    var pageItemLen = app.activeDocument.pages.item(i).pageItems.length 
                    for(j=0;j<pageItemLen;j++) 
                    { 
                        color = 0; scolor =0 
                        if(app.activeDocument.pages.item(i).pageItems.item(j).fillColor.name != "None") 
                            color = app.activeDocument.pages.item(i).pageItems.item(j).fillColor.colorValue 
                        if(app.activeDocument.pages.item(i).pageItems.item(j).strokeColor.name != "None") 
                            scolor = app.activeDocument.pages.item(i).pageItems.item(j).strokeColor.colorValue 
                        if(color == "0,100,0,0" || scolor == "0,100,0,0") 
                              mag=1 
                          var myLayer=app.activeDocument.pages.item(i).pageItems.item(j).itemLayer.name;
                      } 
                } 
            
            
            if(mag==1) 
            { 
                      alert("ERROR: Some Page objects contain Magenta color fill/stroke"+" in "+myLayer) 
                } 
                            else{ 
                            alert("Page objects not contain Magenta color fill/stroke") 
            } 
            

            Regards,

            Karthi

            • 3. Re: Layer name need to include
              Loic.Aigon Adobe Community Professional

              It's likely that your myLayer variable only hosts the last layer name occurence.

               

              You should store all possible values in an array.

               

              var pageLen = app.activeDocument.pages.length   
              var mag=0;
              var myLayersArray = [];
              
              
              for(i=0;i<pageLen;i++)   
              {   
                      var pageItemLen = app.activeDocument.pages.item(i).pageItems.length   
                      for(j=0;j<pageItemLen;j++)   
                      {   
                          color = 0; scolor =0   
                          if(app.activeDocument.pages.item(i).pageItems.item(j).fillColor.name != "None")   
                              color = app.activeDocument.pages.item(i).pageItems.item(j).fillColor.colorValue   
                          if(app.activeDocument.pages.item(i).pageItems.item(j).strokeColor.name != "None")   
                              scolor = app.activeDocument.pages.item(i).pageItems.item(j).strokeColor.colorValue   
                          if(color == "0,100,0,0" || scolor == "0,100,0,0")   
                                mag=1   
                            myLayersArray.push( app.activeDocument.pages.item(i).pageItems.item(j).itemLayer.name);  
                        }   
                  }   
                
                
              if(mag==1)   
              {   
                        alert("ERROR: Some Page objects contain Magenta color fill/stroke"+" in \r"+myLayersArray.join("\r\t-"))   
                  }   
                              else{   
                              alert("Page objects not contain Magenta color fill/stroke")   
              }
              
              • 4. Re: Layer name need to include
                tpk1982 Level 4

                Hi Loic,

                 

                Thank you so much for your kind and quick help.

                 

                I am worst in array concept. I learnt now

                 

                Regards,

                Karthi