2 Replies Latest reply on Oct 31, 2016 11:22 AM by S Hopkins

    Embed textframe into textframe

    martine55225436 Level 1



      I'm currently writing a script to fulfill the following task: Write an arbitrary number of textlines in a textframe. After the last textline, "embed" another inner textframe with border in the textframe and write another line of text in this textframe.


      I create the textframe this way:


      var page = document.pages.item(0);

      var textFrame = page.textFrames.add();

      textFrame.geometricBounds = [10, 10, 100, 100];


      textFrame.contents += "some text in first line";

      textFrame.contents += "\n";

      textFrame.contents += "some text in second line";


      This looks something like this:



      Now I need to add another textframe with a text in it after the last line, so that it looks like this:



      I can't find out how to get the positions for my inner textframe. My only idea was to use the move method:


      var innerFrame = page.textFrames.add();

      innerFrame.contents += "another textframe after all lines";

      innerFrame.paragraphs[0].move(LocationOptions.AFTER, textFrame.insertionPoints[-1]);


      But this only moves the text and not the frame.

      I could also use innerFrame.geometricBounds but I cant find out the x and y starting positions.


      Help is very appreciated.

        • 1. Re: Embed textframe into textframe
          Trevorׅ Adobe Community Professional

          This should help

          var doc, tf1, tf2, foo;
          foo = 'abcdefg'.split('').join('\n');
          doc = app.documents.add();
          tf1 = doc.pages[0].textFrames.add({geometricBounds: ['12.7mm','12.7mm','200mm', '200mm']});
          tf1.contents = foo;
          // check for new line
          if (tf1.characters[-1].contents != '\r') {tf1.insertionPoints[-1].contents = '\r';}
          tf2 = tf1.insertionPoints[-1].textFrames.add();
          tf2.geometricBounds = [tf2.geometricBounds[0], tf2.geometricBounds[1], tf2.geometricBounds[2] + 100, '200mm'];
          tf2.contents = foo;



          1 person found this helpful
          • 2. Re: Embed textframe into textframe
            S Hopkins Adobe Community Professional


            My blog for this week (Oct 31) talks about embedded (inline) text frames. You might find this article will help you understand working with inline text frames, especially when it comes to writing scripts. (yourscriptdoctor.com/blogs)

            S. Hopkins