2 Replies Latest reply on Aug 17, 2010 7:49 AM by TᴀW

    Get all anchored objects (CS4 Javascript)

    TᴀW Adobe Community Professional & MVP

      Hi,

       

      I'm trying to get all anchored objects in a document. This is what I've come up with:

       

       

       

      var myAOs = [];
      myItems = app.activeDocument.allPageItems;
      for (aa=0; aa<myItems.length; aa++){
         if (myItems[aa].parent instanceof Character)  myAOs.push(myItems[aa])
      }

       

       

      Is there a better way to do this?

       

      Thanks,

      Ariel

        • 1. Re: Get all anchored objects (CS4 Javascript)
          Harbs. Level 6

          app.documents[0].stories.everyItem().pageItems.everyItem().getElements();

           

          This will get you all anchored page items except ones in tables and footnotes.

           

          For footnotes, you'd add in an extra footnotes.everyItem()

           

          For Tables, I think .pageItems.everyItem() will work, but I'm not positive.

           

          If you need nested tables, you might want to use tables.allPageItems.

           

          Harbs

          • 2. Re: Get all anchored objects (CS4 Javascript)
            TᴀW Adobe Community Professional & MVP

            Very nifty!

             

            So now I can just tag on:

             

            app.activeDocument.stories.everyItem().pageItems.everyItem().fit(FitOptions.FRAME_TO_CONTE NT)

             

            and hey presto! all anchored objects are reduced to size! Nice and quick, too!

             

            I'm just not entirely clear why the page items of a story are anchored objects, but not the page items of a document?

             

            Thanks,

            Ariel