7 Replies Latest reply on Apr 11, 2014 4:19 AM by Trevorׅ

    Select item(s) in layer

    AsOne

      Hi all,

       

      How do I select Item(s) in specific layer name

       

      my code is

      var layer=app.activeDocument.layers.everyItem().getElements("Info Layer");

       

      can any one correct this, help will be appreciate

       

       

      Thanks

      Steve

        • 1. Re: Select item(s) in layer
          Sajeev Sridharan Level 4

          myObject = app.documents[0].pageItems;

          for (var i=0; i <myObject.length; i++)

          {

              if(myObject[i].itemLayer.name=="Info Layer")

              {

                  myObject[i].select();

              }

          }

           

          Vandy

          1 person found this helpful
          • 2. Re: Select item(s) in layer
            Trevorׅ Adobe Community Professional

            Hi Steve & Vandy

             

            No need to do a loop

             

             

            Turn all Items yellow

            app.activeDocument.layers.itemByName("Layer 1").pageItems.everyItem().fillColor = "Yellow"
            

             

            Get Elements

             

            myLayersItems = app.activeDocument.layers.itemByName("Layer 1").pageItems.everyItem().getElements()
            

             

            Trevor

            • 3. Re: Select item(s) in layer
              csm_phil Level 4

              Hi Steve,

               

              Please try the below JS code, I just alernate the vandy method.

               

               

              var myDoc = app.activeDocument;
              var mylayer = myDoc.layers.itemByName("Layer 2");
              for (var i=0; i <mylayer.allPageItems.length; i++){
                      mylayer.allPageItems[i].select();
                      }
              

               

               

              thx,

              csm_phil

              • 4. Re: Select item(s) in layer
                csm_phil Level 4

                HI Trevor,

                 

                I have a doubt with the below js lines, If steve want to move the particular layer page items. In this case the below lines not working, So we have to loop it? Because he request to select the particular layer page items. so that, vandy loop the page items right!

                 

                Turn all Items yellow

                app.activeDocument.layers.itemByName("Layer 1").pageItems.everyItem().fillColor = "Yellow"
                

                 

                Get Elements

                 

                myLayersItems = app.activeDocument.layers.itemByName("Layer 1").pageItems.everyItem().getElements()
                

                 

                thx,

                csm_phil

                • 5. Re: Select item(s) in layer
                  Trevorׅ Adobe Community Professional

                  Sorry Phil, I don't agree with you on this.

                   

                  There is very rarely a case for "Selecting" an object,

                  To move the all the items to another layer one would just use

                   

                  app.activeDocument.layers.itemByName("Layer 1").pageItems.everyItem().move(app.activeDocument.layers.itemByName("Layer 2"))
                  

                   

                  Trevor

                  • 6. Re: Select item(s) in layer
                    Dave Saunders Level 4

                    Let's just clarify that Trevor's examples work only if the active document has layers with the exact names he's using in his sample code.

                     

                    Dave

                    • 7. Re: Select item(s) in layer
                      Trevorׅ Adobe Community Professional

                      But with a limited amount of imagination it can be quite easily adapted