6 Replies Latest reply on Jul 15, 2014 9:53 AM by curiousgeorgex1

    Create and Link a TextFrame for each page

    curiousgeorgex1

      New to InDesign scripting I am trying to find a way to create a text frame in a document up at the top left of each page with text that will link in between a text frame using ExtendScript Toolkit.  I tried to reference class textframe but couldn't see where to be able to manipulate the anchor to the other textframe.

       

      Such as:

       

      Screen Shot.png

       

      So textframe Lorem's anchor will be dropped at the beginning of Bacon.  Currently using InDesign CC-2014.  Any help would be great thanks!  I am aware how to could create a text frame in the master but at this time I do not want to do it that way.

        • 1. Re: Create and Link a TextFrame for each page
          Jump_Over Level 5

          Hi,

           

          Specify what you mean saying "link" and "anchor".

           

          Creating linked textFrames or one anchored into another ==> two different stories.

           

          Jarek

          • 2. Re: Create and Link a TextFrame for each page
            curiousgeorgex1 Level 1

            If I click on texframe Lorem to go in between the textframe Bacon. 

             

            Screen Shot 2014-07-09 at 8.04.29 AM.png

             

            Per this on Threaded text frames on multiple pages I am trying to make a text frame for every page at the top left corner that can be anchored to the beginning of that page's text frame.

            • 3. Re: Create and Link a TextFrame for each page
              Dave Saunders Level 4

              You can't anchor one text frame with another. Anchors appear in text (which generally means its inside a text frame).

               

              Ah, but now I'm thoroughly confused because the article you pointed to doesn't have anything to do with anchoring.

               

              So what are you trying to do?

               

              Are the frames on the pages threaded? You can't anchor a threaded frame to another story -- only stand-alone frames can be anchored.

               

              Are you trying to write a script to create new text frames to be anchored to an existing story? Or are you trying to work with frames that already exist?

               

              Dave

              • 4. Re: Create and Link a TextFrame for each page
                Laubender Adobe Community Professional & MVP

                @curiousgeorgex1 – unfortunately there is no method available in scripting that mimics what you can do in the UI when you drag the tiny square of the text frame to an insertion point.

                 

                In scripting we have several methods to anchor a text frame to an insertion point:

                 

                1. The add() method that would add a new text frame to an insertion point.

                All options that define the position are made after.

                2. Move or duplicate a character, that resembles an already anchored object to an insertion point.

                3. Copy/paste an object to a selected insertion point, define position after

                 

                The easiest method is option 2, if you have prepared a textframe that is already anchored to another one at the right position. It might be more flexible to chose a position relative to the page's edges to compensate for various positions of the text frame on your page (sorry for my German UI):

                 

                Benutzerdefiniert => Position: Custom
                Reletiv zum Bund => Relative to Spine

                Bezugspunkt => Reference Point
                Verankerte Position => Anchored Position

                Verankertes Objekt => Anchored Object

                x relativ zu: Seitenkante => x Relative To: Page Edge

                x-Versatz => x Offset: 0

                y relativ zu: Seitenkante => y Relative To: Page Edge

                y-Versatz => y Offset: 0

                 

                AnchoredTextFramePositionRelativeToPage.png

                 

                With this setting the anchored text frame will always sit at the upper left corner of an even page and in the upper right corner of a odd page in a double-sided document. The parent text frame might be anywhere on the page. Here the situation with a duplicate of the text frame with the anchored one on a right page. Note: the position of the parent text frame is somewhere else on the page, but the anchored one is still on the outer upper edge of the page:

                 

                DuplicateOnRightPage.png

                Now that we have prepared the "anchordness" without scripting, we could, with or without scripting, copy the only character in the parent text frame and paste it to any insertion point of a text frame on a page and the anchored text frame will be positioned on the right or left upper edge of the page.

                 

                Move your prepared text frame (the parent of the anchored one) to the pasteboard.

                 

                MoveParentToPasteboardForPreparation.png

                 

                Select the prepared text frame on the pasteboard and run the following code snippet (ExtendScript / JavaScript):

                 

                //Get the character that holds the anchored text frame:
                var myAnchorCharacter = app.selection[0].characters[0];
                
                //Get all pages in the document:
                var myPages = app.documents[0].pages.everyItem().getElements();
                
                //Loop through all pages:
                for(var n=0;n<myPages.length;n++){
                   
                    //If the page contains text frames
                    if(myPages[n].textFrames.length > 0){
                       
                        //Duplicate my anchor character before the first insertion point of the first text frame of that page:
                        myAnchorCharacter.duplicate(LocationOptions.BEFORE,myPages[n].textFrames[0].insertionPoints[0]);
                       
                        };
                   
                    };
                

                 

                Before running the snippet (text frame on pasteboard is selected):

                 

                BeforeExecutingSnippet.png

                 

                After running the snippet:

                 

                AfterExecutingSnippet.png

                 

                Doing option number 1 requires far more code, but also doable.

                 

                Uwe

                • 5. Re: Create and Link a TextFrame for each page
                  Obi-wan Kenobi Adobe Community Professional

                  Hi,

                   

                  Has someone asked this:

                   

                  Why do you want to create such a block? or: To put what in it?

                  • 6. Re: Create and Link a TextFrame for each page
                    curiousgeorgex1 Level 1

                    Trying to set an epub:type from InDesign.  Only on fixed layout can I get it to work but in a reflowable ePub anything that has been created in the master with a Type Special Character's Current Number will not export.