6 Replies Latest reply on Apr 26, 2013 12:09 AM by Vamitul

    list images for a visible layers only

    BEGINNER_X Level 3

      Hi,

       

      I need images name for the layers visible is "true "only.

       

      i.e., document contains 10 images, but the conditions is (layers visible = true) then document images is 7.

       

       

      Trying Code:
      
      var myDoc = app.activeDocument
      
      var myGraphics = app.activeDocument.allGraphics
      
      alert("docMyGraphics " + myGraphics.length)
      
      var myLayer = app.activeDocument.layers.everyItem().getElements()
      
      for(k=0; k<myLayer.length; k++)
      {
          if(myLayer[k].visible == true)
          {
              for(i=0; i<myGraphics.length; i++)
              {
                  alert(myGraphics[i].itemLink.name)
                  }
              }
          }
      

       

      Could anyone rewrite my code and give solution.

       

      Plz it is very urgent.....

       

      Thanks

      Beginner

        • 1. Re: list images for a visible layers only
          SureshRaji

          Hi

           

          Try this:

           

          var myDoc = app.activeDocument

           

          var myGraphics = app.activeDocument.allGraphics

           

          alert("docMyGraphics " + myGraphics.length)

           

          var myLayer = app.activeDocument.layers.everyItem().getElements()

           

          for(k=0; k<myLayer.length; k++)

          {

              if(myLayer[k].visible == true)

              {

                  for(i=0; i<myGraphics.length; i++)

                  {

                      if(myGraphics[i].itemLayer == myLayer[k])         // Check the item is in visible layer

                           alert(myGraphics[i].itemLink.name)

                      }

                  }

              }

          1 person found this helpful
          • 2. Re: list images for a visible layers only
            BEGINNER_X Level 3

            Hi Selvaraj,

             

            Thanks for your quick response.....

             

            Its working fine. I have given points as a helpful answer to you.

             

            Thanks

            Beginner

            • 3. Re: list images for a visible layers only
              -hans- Level 4

              Hi,

               

              a layer's got a own property allGraphics

              • 4. Re: list images for a visible layers only
                Vamitul Level 4

                Hey Beginner, hey Suresh.

                http://jongware.mit.edu/idcs5/pc_Layer.html

                Each layer has it's own "allGraphics property, so a nicer way of doing is to use that:

                 

                 

                var doc = app.activeDocument;
                var myLinks = [];
                for (var i = 0; i < doc.layers.length; i++) {
                          if (doc.layers[i].visible) {
                                    myLinks.push("Layer "+i+"("+doc.layers[i].name+"):")
                                    var layerGraph = doc.layers[i].allGraphics;
                                    for (var j = 0; j < layerGraph.length; j++) {
                                              try {                                        //  not all graphics have a itemLink, for example the embedded ones
                                                        myLinks.push(layerGraph[j].itemLink.name);
                                              } catch (e) {
                                                        myLinks.push("Error: Graphic " + j + " on layer " + i + " might be embedded");
                                              }
                
                
                                    }
                          }
                }
                alert (myLinks.join("\r"));
                
                
                • 5. Re: list images for a visible layers only
                  SureshRaji Level 2

                  Hi Vamitul

                   

                  Thankyou for showing me the easiest way.

                   

                   

                  doc.layers[i].allGraphics

                  • 6. Re: list images for a visible layers only
                    Vamitul Level 4

                    one caveat: allGraphic, no matter weather it's on layer or doc (and as a matter of fact every property that starts with "all" - allParagraphStyles, allPageItems etc etc) returns a array, not a collection, so you can't use all the cool stuff (like everyItem) on it.

                    Marc has some excelent stuff here:

                     

                    http://www.indiscripts.com/post/2010/07/on-everyitem-part-2