20 Replies Latest reply on Jul 28, 2010 3:11 AM by Marijan Tompa [tomaxxi]

    [CS3][JS] everyItem() and getElements()

    (Simon_Paterson)
      I am trying to work out how everyItem() and getElements() work. In the following snippet I'm trying to get the top margin of every page to change, without using a loop. (I realise I could do this with masterpages, but that isn't the point of this exercise.) I'm unsure of the circumstances where I need to loop or which circumstances I can/should use everyItem() and getElements().

      var myTopMargin = 25;
      var myMarginPreferences = app.documents[0].pages.everyItem().marginPreferences; // This returns an array of marginPreference objects
      with (myMarginPreferences) {
      top = myTopMargin;
      }

      This didn't work.

      I also tried:

      var myTopMargin = 25;
      var myMarginPreferences = app.documents[0].pages.everyItem();
      with (myMarginPreferences) {
      marginPreferences.top = myTopMargin;
      }

      Can anyone demystify the use of everyItem() and getElements()?

      For example, expanding the above example, how do I get an array of all the top margin settings of every page?

      var myTopMargins = app.documents[0].pages.everyItem().marginPreferences.top; // undefined result

      Perhaps there is simply no need to do this? Should I just iterate through the items? (I come from an AppleScript background and this was always slower than obtaining all the information at once, which is where this question comes from.)

      Thank you for your time.