9 Replies Latest reply on Jul 25, 2011 2:21 AM by [Jongware]

    Link unthreaded text frame to threaded text frames

    Boesiger Pia

      Can someone please help with a js script (for ID 5.5) that links an unthreaded textframe to threaded ones. I tried

       

      myTextFrameA.nextTextFrame = myTextFrameB;

       

      it messes things up as soon as I've got to link more than once, which of course I have to (would I need a script otherwise?).

       

      Thanks for your help.

        • 1. Re: Link unthreaded text frame to threaded text frames
          [Jongware] Most Valuable Participant

          Boesiger Pia wrote:

           

          .. it messes things up as soon as I've got to link more than once, which of course I have to ..

           

          Well, I'd have to see the script before being able to say waht you did wrong, but I bet it's real simple: if

           

          myTextFrameA.nextTextFrame = myTextFrameB;

           

          works, then you should not link your next text frame to myTextFrameA as well. Link it to myTextFrameB instead! And the next frame after this new one needs to be linked to this next frame of B, and so on and so forth.

          • 2. Re: Link unthreaded text frame to threaded text frames
            [Jongware] Most Valuable Participant

            doh.jpeg

             

            Of course it's not that complicated. Since you are threading frames together to form a coherent story, all you need to do is link each new frame to the very first one with this

             

            myTextFrameA.endTextFrame.nextTextFrame = myNextFrame;

            • 3. Re: Link unthreaded text frame to threaded text frames
              Boesiger Pia Level 1

              Thanks Jongware for your contribution. It doesn't work for my case, though. Due to the fact that I didn't make myself clear...

               

              So, from scratch. Let's assume I have a document of 100 pages with 100 textframes all threaded neatly together. What I have to to do now is to place an additional textframe (without text) on every couple of pages and link it in.

              This here works fine enough, but the threading part is beyond me:


              var myDoc = app.activeDocument;
              var myFrame = app.selection[0].parentTextFrames[0];
              myFrame.geometricBounds = ["42","23.5","267","186.5"];
              myFrame.strokeWeight = 0.75;
              myFrame.textFramePreferences.insetSpacing = ["2","2","2","2"];


              var myPage = app.activeWindow.activePage;
              var myNewFrame = myPage.textFrames.add();
              myNewFrame.geometricBounds = ["30","23.5","42","186.5"];

               

              By the way, I'd rather have the frame activated than the cursor set initially, but don't know how to program... I bet it's simple.

              • 4. Re: Link unthreaded text frame to threaded text frames
                John Hawkinson Level 5

                Err, isn't this sufficient?:

                 

                myFrame.nextTextFrame = myNewFrame;
                

                 

                By the way, I'd rather have the frame activated than the cursor set initially, but don't know how to program... I bet it's simple.

                I'm sorry, what? Please rephrase your question.

                • 5. Re: Link unthreaded text frame to threaded text frames
                  Boesiger Pia Level 1

                  Unfortunately no. It messes up the coherency of the story the way the code was written.

                  I reordered it. The new frame will be added AFTER, instead of before, the existing frame, and - oh wonder - it works. So, many thanks to getting me there.

                   

                  As for my other question. I have to choose the "type tool" and actually set the cursor into the text to get the script running. If I choose the frame with the "selection tool" I get an error message. I mean I can handle this, but it would be much more convenient just to choose the frame to start running the script.

                  • 6. Re: Link unthreaded text frame to threaded text frames
                    [Jongware] Most Valuable Participant

                    Boesiger Pia wrote:

                    [..]

                    As for my other question. I have to choose the "type tool" and actually set the cursor into the text to get the script running. If I choose the frame with the "selection tool" I get an error message. I mean I can handle this, but it would be much more convenient just to choose the frame to start running the script.

                     

                    Ah, now that part *is* easy. It's because you refer to 'the parent frame of the selection', and that only works if you are *inside* the text frame you want to start with.

                     

                    Change this line

                     

                    var myFrame = app.selection[0].parentTextFrames[0];

                    to these

                     

                    var myFrame;
                    switch (app.selection[0].constructor.name)
                    {
                      case "InsertionPoint": myFrame = app.selection[0].parentTextFrames[0]; break;
                      case "TextFrame": myFrame = app.selection[0]; break;
                      default: alert ("Uh oh. You're going to need a bigger script"); return;
                    }
                    
                    • 7. Re: Link unthreaded text frame to threaded text frames
                      Boesiger Pia Level 1

                      Running it I get an error message. It's got to do with the "return; command" which seems to be placed incorrectly outside a function-body (wording might not be accurate as translated).

                      What's wrong with it?

                      • 8. Re: Link unthreaded text frame to threaded text frames
                        [Jongware] Most Valuable Participant

                        Oops -- I didn't try before posting. The idea was to force the script to stop when you selected something else, and in general a 'return' is enough.

                         

                        Change the 'return' to 'exit(0)' will make it grind to a halt when required.

                        • 9. Re: Link unthreaded text frame to threaded text frames
                          Boesiger Pia Level 1

                          Now it works.

                          Thanks a lot!