4 Replies Latest reply on Nov 8, 2009 5:49 AM by Harbs.

    nextTextFrame

    S.Biancardo Level 1

      Hi exist a command in javascritp that allow to continue a textframe when it is in overflows?

      i have try the nextTextFrame but this command not automatic position the object in the page and not create automaticaly textframe and page if is overflow.

      Thank you

        • 1. Re: nextTextFrame
          [Jongware] Most Valuable Participant

          That is correct. (Alas.) You must create a new text frame and position it, then you can set the previous one's nextTextFrame to point to this new one.

           

          When placing a text file, you have to option to enable "autoflow" but when manually adjusting frames it's not an option.

          • 2. Re: nextTextFrame
            Harbs. Level 6

            This probably doesn't help the OP, but I couldn't resist...

             

            AutoFlow Pro includes a scripting function for autoflowing stories. It uses AF Pro's very complex flowing mechanism (which is way better than the standard one in InDesign...)

             

            Below is a full script which tells AutoFlow Pro to autoflow the currently selected story:

             

            var myDoc = app.documents[0];
            var myStory = app.selection[0].parentStory;
            var autoFlowPro = myDoc.loadedScriptedPlugins("autoflowpro")[0];
            autoFlowPro.handleScriptEvent ("externalFlowStory",String(myStory.id));
            

             

            Harbs

            • 3. Re: nextTextFrame
              [Jongware] Most Valuable Participant

              Compared to Harbs' few lines, this method is a bit more difficult to follow. But -- it works.

               

              if (app.selection.length != 1)
               complain ("Eh. You oughta have one (and only one) text frame selected...");
              startFrame = app.selection[0];
              if (startFrame.constructor.name != "TextFrame")
               complain ("Honestly, this only works on a text frame...");
              app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
              while (startFrame.overflows)
              {
              // 1. Grab current page
               currPage = startFrame.parent;
               if (!(currPage instanceof Page))
                complain ("Why? Why? Why?");
              // 2. Add a new one
               newPage = app.activeDocument.pages.add (LocationOptions.AFTER, currPage);
              // 3. Show it :-)
               app.activeWindow.activePage = newPage;
              // 4. Create a new text frame here
               anotherFrame = newPage.textFrames.add ();
              // 5. .. and position it onto the margins
               anotherFrame.geometricBounds = [ app.activeDocument.marginPreferences.top,
                app.activeDocument.marginPreferences.left,
                app.activeDocument.documentPreferences.pageHeight - app.activeDocument.marginPreferences.bottom,
                app.activeDocument.documentPreferences.pageWidth - app.activeDocument.marginPreferences.right ];
              // 6. -- then finally link it:
               startFrame.nextTextFrame = anotherFrame;
              // 7. [Sanity Check] Is the new frame empty?
               if (anotherFrame.contents.length == 0)
                complain ("Could not place any more text here");
              // 8. Swap around to continue
               currPage = newPage;
               startFrame = anotherFrame;
              }
              function complain (reason)
              {
               alert ('An error has occurred. Most likely, it\'s your own fault.\n\n"'+reason+'"');
               exit(0);
              }
              

               

              There are a few improvements you might want to consider. It doesn't specify a master page -- it uses whatever was active on the original page. The margins are taken from the current document setup -- if your master page uses others, you should grab the values from there. It also doesn't take different left/right margins into account.

              It changes the page ruler to a per-page view, just because it is easier to position the text frames!

              • 4. Re: nextTextFrame
                Harbs. Level 6

                Nice work Jong!

                 

                Just a few gotchas:

                 

                1) textframe.overflows is not a foolproof method. It only returns true 

                if the text is overflown-- not if a table or footnote overflows.

                2) a long table will stop that script in its tracks.

                3) Start on next/even page will also stop it.

                 

                Of course it doesn't deal with master text frames or text frame 

                properties.

                 

                An easy way do make sure the new text frame has the same properties as 

                the original is to use textFrame.duplicate(), but I quickly learned 

                that it's not advisable, because it drastically increases the 

                probability of corrupted text frames...

                 

                So be careful with using Jong's script for wide-purpose usage, but for 

                a quick solution, it's great!

                 

                Harbs