4 Replies Latest reply on Nov 1, 2010 1:09 AM by tansk02

    How to find Images and Text on different layers

    tansk02

      HI all,

       

      Is anybody has a  js script code which alert if my images are on my text layer and my text is on my image layer?

       

      Please help me out.

       

      Thanks in advance

        • 1. Re: How to find Images and Text on different layers
          Harbs. Level 6

          Try this:

           

          main();
          function main(){
              var doc = app.documents[0];
              var textLayer = doc.layers.item("Text Layer");
              var imageLayer = doc.layers.item("Image Layer");
          
              var pis = doc.pageItems.everyItem().getElements().slice();
              for(var i=0;i<pis.length;i++){
                  if(pis[i] instanceof TextFrame){
                      if(pis[i].itemLayer != textLayer){
                          beep();
                          pis[i].select();
                          showIt();
                          return;
                      }
                  } else {
                      if(pis[i].itemLayer != imageLayer){
                          beep();
                          pis[i].select();
                          showIt();
                          return;
                      }
                  }
              }
          }
          function showIt() {
              var myZoom = app.activeWindow.zoomPercentage;
              app.activeWindow.zoom(ZoomOptions.showPasteboard);
              app.activeWindow.zoomPercentage = myZoom;
          }
          
          

           

          Harbs

          1 person found this helpful
          • 2. Re: How to find Images and Text on different layers
            tansk02 Level 1

            Thanks, Herbs.

             

            It shows empty rectangle (graphic frames) too. Is there any possibility to show only images placed on wrong layer.

             

            One more thing. I need an alert message having info about no. of wrong placement of Images and textboxes if any.

             

             

            thanks for your valuable time.

            • 3. Re: How to find Images and Text on different layers
              Haakenlid Level 3

              Like this? This will also move the page item to the "correct" layer. I'm not sure if that's what you want, though.

               

              main();
              function main(){
                  var doc = app.activeDocument;
                  var textLayer = doc.layers.item("Text Layer");
                  var imageLayer = doc.layers.item("Image Layer");
                  var misplacedImages = 0;
                  var misplacedTextFrames = 0;
                  var pis = doc.pageItems.everyItem().getElements().slice();
                  for(var i=0;i<pis.length;i++){
                      if(pis[i] instanceof TextFrame){
                          if(pis[i].itemLayer != textLayer){
                               misplacedTextFrames++;
                               pis[i].move(textLayer); // moves the textframe to the text layer
                          }
                      } else {
                          if(pis[i].itemLayer != imageLayer&&pis[i].graphics.length==1){
                         misplacedImages++;
                         pis[i].move(imageLayer); // moves the image to the image layer
                       }
                      }
                  }
                  alert ("Report\rmisplaced images: "+misplacedImages+"\rmisplaced textframes: "+misplacedTextFrames);
              }