6 Replies Latest reply on May 23, 2014 10:36 AM by davidnest

    moving images and text to layers

    davidnest

      I've managed to cobble together a script that moves all images and text to layers. I intend to create an if else statement that checks if layers exist, but my question is: is there any way to exclude the master pages from this?

      Thanks,

      ~David

       

      -----

      pictureLayer = app.activeDocument.layers.item ("images");

      textLayer= app.activeDocument.layers.item ("text layer");

      app.activeDocument.rectangles.everyItem().itemLayer = pictureLayer;

      app.activeDocument.textFrames.everyItem().itemLayer = textLayer;

        • 1. Re: moving images and text to layers
          Jump_Over Level 5

          Hi,

           

          include pages.everyItem() as parents:

           

          ...

          app.activeDocument.pages.everyItem().rectangles.everyItem().itemLayer = pictureLayer;

          app.activeDocument.pages.everyItem().textFrames.everyItem().itemLayer = textLayer;

          ...

           

          Jarek

          • 2. Re: moving images and text to layers
            Laubender Adobe Community Professional & MVP

            @David – or, if you want to include items on the pasteboard, use spreads instead of pages.

             

            var myDoc = app.activeDocument;
            
            if(!myDoc.layers.itemByName("textLayer").isValid){myDoc.layers.add({name:"textLayer"})};
            if(!myDoc.layers.itemByName("pictureLayer").isValid){myDoc.layers.add({name:"pictureLayer"})};
            
            var textLayer = myDoc.layers.itemByName("textLayer");
            textLayer.locked = false;
            
            var pictureLayer = myDoc.layers.itemByName("pictureLayer");
            pictureLayer.locked = false;
            
            myDoc.spreads.everyItem().textFrames.everyItem().locked = false;
            myDoc.spreads.everyItem().textFrames.everyItem().itemLayer = textLayer;
            
            myDoc.spreads.everyItem().rectangles.everyItem().locked = false;
            myDoc.spreads.everyItem().rectangles.everyItem().itemLayer = pictureLayer;
            

             

            Uwe

            • 3. Re: moving images and text to layers
              davidnest Level 1

              This works great, unless the images are not in rectangles. Is there a way around that?

              • 4. Re: moving images and text to layers
                Jump_Over Level 5

                Hi,

                 

                splineItems.everyItem() ==> includes recs, ovals, polygons, graphicLines

                 

                Jarek

                • 5. Re: moving images and text to layers
                  Laubender Adobe Community Professional & MVP

                  @David – you say "not in rectangles". Hm. What does this mean? Exactly?


                  Using ExtendScript (JavaScript) is a work of precison. You need to have a very good notion what is the exact situation your document, your page items are in, before writing a script.

                   

                  Shortcuts, ways that act globally on every item are often dead ends, because after some testing you realise: an exception here, an exception there.

                   

                  So it might be useful to depart from everyItem() and looking at Links objects or allGraphics in the object model and loop through setting the itemLayer of their container objects. And that could fail, too, because they are nested into other objects (see, complexity is rising quick…).

                   

                  Uwe

                  • 6. Re: moving images and text to layers
                    davidnest Level 1

                    This worked great thanks. Here is my final script. I really appreciate everyones help.

                     

                    var myDoc = app.activeDocument; 

                     

                    if(!myDoc.layers.itemByName("pictureLayer").isValid){myDoc.layers.add({name:"pictureLayer" })}; 

                    if(!myDoc.layers.itemByName("textLayer").isValid){myDoc.layers.add({name:"textLayer"})}; 

                     

                    var textLayer = myDoc.layers.itemByName("textLayer"); 

                    textLayer.locked = false; 

                     

                    var pictureLayer = myDoc.layers.itemByName("pictureLayer"); 

                    pictureLayer.locked = false; 

                     

                    myDoc.spreads.everyItem().textFrames.everyItem().locked = false; 

                    myDoc.spreads.everyItem().textFrames.everyItem().itemLayer = textLayer; 

                     

                    myDoc.spreads.everyItem().splineItems.everyItem().locked = false; 

                    myDoc.spreads.everyItem().splineItems.everyItem().itemLayer = pictureLayer;