3 Replies Latest reply on Sep 4, 2008 9:29 AM by (Joel_Bellot)

    Working With All Items on a Page and a Layer

      I would like to rotate all items in a document using javascript. I have reached a dead end when it comes to selecting/collecting/grouping all object on each page and on each layer separately.

      Since LAYERS and PAGES are both objects of DOCUMENT, I can't seem to select or group allItems of a page of a layer if you see what I mean.

      Any help would be appreciated.

      So far i have
      with (app.activeDocument){
      var TheItems = pages.item(0).allPageItems; // either/or the line below
      var TheItems = layers.item(0).allPageItems; // either/or the line above
      var myGroup = pages.item(0).groups.add(TheItems);
      }

      Thanks
        • 1. Re: Working With All Items on a Page and a Layer
          Peter Kahrel Adobe Community Professional & MVP
          You'll probably have to collect all page items on a page, then iterate through them checking what layer they're on. Something like this:

          myPages = app.activeDocument.pages;
          
          for (i = 0; i < myPages.length; i++)
             {
             p_items = myPages[i].allPageItems;
             for (j = 0; j < p_items.length; j++)
                {
                switch (p_items[j].itemLayer.name)
                   {
                   case 'Layer 1': // do this
                   case 'Layer 2': // do that
                   case 'Layer 3': // do the other
                   }
                }
             }


          Peter
          • 2. Re: Working With All Items on a Page and a Layer
            Level 1
            allPageItems is not the right property to use. That includes page items that are grouped already or anchored to text. You should just use the pageItems collection if your plan is to group them.

            Groups are constrained to be within a spread, so using the layers collection isn't likely to work, although it could if all the items on a particular layer were actually on a single spread.

            This is a case where AppleScript's whose statement is very useful. In JavaScript, you have to iterate through a collection pushing each one you actually want to work with on to an array, then group the members of the array.

            Dave
            • 3. Re: Working With All Items on a Page and a Layer
              Level 1
              Thanks Guys,

              I thought it might be complicated!

              Joel