1 Reply Latest reply on Mar 5, 2011 2:02 AM by John Hawkinson

    Add text to rectangle - Alternate rectangles

    Rums Level 1


      I have a document with several rectangles and I need to take the label of each rectangle and add it as a text to that rectangle.

      var newFile = new File ("<file path>");

      var myDocument = app.open(newFile);

      var pages = myDocument.pages;

      var myPage = pages[0];

      var rectangles = myPage.rectangles;


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

      var rectangle = rectangles.item(i);

      rectangle.contentType = ContentType.TEXT_TYPE;

      rectangle.contents = rectangle.label;



      This, for some reason works on alternate rectangles. That is, if I have 5 rectangles in my document, rectangle 1,3 and 5 have their contents populated with their labels while rectangles 2 and 4 are not. there are no other errors. any idea on what I am missing?



        • 1. Re: Add text to rectangle - Alternate rectangles
          John Hawkinson Level 5

          When you change a rectangle's contentType, you change it from a rectangle to a TextFrame, thus changing the number of rectangles, causing you to miss the next rectangle in your loop. Try counting down instead of up.


          app.activeDocument.rectangles[0].contentType = ContentType.TEXT_TYPE