6 Replies Latest reply on Jul 14, 2014 3:30 PM by myDavey

    Rethread all text frames by current page order

    myDavey Level 1

      Hello

      I made a 'mistake' today, wondering if there is anything to do about it

      • I have an InDi file with 1 story - multi chapter
      • every page is a new chapter (small chapters)
      • I wanted to change the order, so I moved the pages! (not the text)
      • Now, when I am on page 12, if I add text, or press the down arrow, it is going into page 3! etc.

       

      Is there a way to rethread all text frames?

      I.e., break the current threading, and then rethread each page's frame to the next?

       

       

      Any help and guidance will be appreciated

      Thanks

      Davey

        • 1. Re: Rethread all text frames by current page order
          Jump_Over Level 5

          Hi,

           

          Backup your doc and run this:

          (one of threated textFrames supposed to be selected)

          var
            mFrames = app.selection[0].parentStory.textContainers,
            len = mFrames.length,
            cTxtReflowSet = app.activeDocument.textPreferences.smartTextReflow;
          
          app.activeDocument.textPreferences.smartTextReflow = false;
          
          while (len-->0) {
            mFrames[len].nextTextFrame = null;
            }
          mFrames.sort(sortByPage);
          len = mFrames.length;
          
          while (len-->1)
            mFrames[len].previousTextFrame = mFrames[len-1];
          
          app.activeDocument.textPreferences.smartTextReflow = cTxtReflowSet;
          
          function sortByPage (a,b) {
            return a.parentPage.documentOffset > b.parentPage.documentOffset;
            }
          
          

           

          Jarek

          • 2. Re: Rethread all text frames by current page order
            myDavey Level 1

            Hi Jarek

            Thanks a lot for your response

            I dont think this is working properly

            It seems to me that it is putting it back to the order in which it was originally

            Instead, I wanted to thread the text as it appears in the current page order

             

            Thanks

            Davey

            • 3. Re: Re: Rethread all text frames by current page order
              Jump_Over Level 5

              Yeap,

               

              The problem is only you can see how it appears. I can just read what you wrote, nothing else.

              You shouldn't ask for "re-threading" frames if your goal is to recompose text. There are different stories.

              I gave you a code to step back from a mistake you wrote about.

               

              To reach a goal with recomposing I suggest workflow like:

              • duplicate a doc
              • remove main story
              • link frames as page order
              • duplicate particular texts page by page from original doc to a copy

               

              Assuming 3 steps are done - 4th depends on your doc structure (how many frames on page, how to detect a proper textFrame, is it named?)

               

              Lets assume you did an empty copy with textFrame linked in page order and there is only one frame per page and a story starts from 1st page.

              Keep source and output opened and activate a source. Then run this:

              var
                sourceDoc = app.activeDocument,
                outputDoc = app.documents[1],
                myTextArray = sourceDoc.pages.everyItem().textFrames.everyItem().texts.everyItem().getElements();
              for (var k=0; k<myTextArray.length; k++)
                myTextArray[k].duplicate(LocationOptions.AFTER, outputDoc.pages[0].textFrames[0].parentStory.texts[0] );
              

               

              Jarek

              • 4. Re: Re: Rethread all text frames by current page order
                myDavey Level 1

                Hi Jarek

                Thanks a lot - greatly appreciated!

                Sorry for the confusion, I guess I just didnt have the right terminology.

                 

                _________

                 

                Now, it seems that you are on a much more professional level than me..... I dont understand what you mean

                1. What do you mean by "remove main story"?
                2. When you say "link frames as page order" do you mean by script? Otherwise - how?
                3. I am not sure why #4 is needed.

                 

                 

                Every page has one frame, and originally they were threaded in order of pages.

                Then I re-ordered the pages.

                Would'nt it suffice to just break the current threading and to then rethread it by page order?

                I am making it sound simple, but I dont know how to accomplish this

                 

                 

                Thanks again

                Davey

                • 5. Re: Re: Re: Rethread all text frames by current page order
                  Kai Rübsamen Adobe Community Professional

                  I’m not sure, if I understand the goal correctly and we talk about the same things if we talk about recomposing or re-threading.

                   

                  I would do the following:

                  1. Use Adobes script split story. This will duplicate all Frames and delete the origin story

                  2. Re-Thread the frames in the order as shown on the document pages

                  3. To prevent any other frames on the page, give the frames before re-threading or recomposing ;-) a name

                   

                  // check selection
                  if ( !( app.selection.length == 1 && ( app.selection[0].hasOwnProperty('baseline') || app.selection[0].constructor.name == "TextFrame" ) )) {
                      alert( "wrong selection!" );
                      exit();
                  }
                  var curStory = app.selection[0].parentStory;
                  var curDoc = app.activeDocument;
                  
                  if ( curStory.textContainers.length > 1 ) {
                      mySplitStory( curStory );
                      myRemoveFrames( curStory );
                  }
                  
                  relinkTextFrames ( curDoc.textFrames );
                                  
                  function mySplitStory( myStory ) {
                      var myTextFrame;
                      //Duplicate each text frame in the story.
                      for( var myCounter = myStory.textContainers.length-1; myCounter >= 0; myCounter -- ) {
                          myTextFrame = myStory.textContainers[myCounter];
                          myTextFrame.name = "linkme";
                          myTextFrame.duplicate();
                      }
                  }
                  function myRemoveFrames( myStory ) {
                      //Remove each text frame in the story. Iterate backwards to avoid invalid references.
                      for( var myCounter = myStory.textContainers.length-1; myCounter >= 0; myCounter -- ) {
                          myStory.textContainers[myCounter].remove();
                      }
                  }
                  
                  function relinkTextFrames( myTextFrames ) {
                      var collectTFrames = [];
                      for (var i = 0; i < myTextFrames.length; i++ ) {
                          if ( myTextFrames[i].name == "linkme" ) {
                              collectTFrames.push(myTextFrames[i]);
                          }
                      }
                      for ( var n = 0; n < collectTFrames.length-1; n++ ) {
                          var curTFrame = collectTFrames[n];
                          var nextTFrame = collectTFrames[n+1];
                          curTFrame.nextTextFrame = nextTFrame;
                      }
                  }
                  
                  • 6. Re: Re: Re: Rethread all text frames by current page order
                    myDavey Level 1

                    Hi Kai

                    That's exactly what I needed! - Worked perfectly

                    Thanks a lot!

                     

                    Davey