11 Replies Latest reply on Jun 23, 2015 11:16 AM by LenZigante

    [CS5][JS] Update TextFrame contents with overflow??

    lhanneman Level 1

      Hello,

       

      I'm running into a problem with a script that updates the text in a textframe. If the text that I'm putting into the new textframe causes an overflow, all of the overflow text seems to be jumbled and formatted differently. I can test/prove this by running my script on a small text frame, then when its complete, I can go to Indesign and expand the text frame to see the bad text. However if I leave the text frame expanded and run my script again, it works perfectly. Is there a setting I could be missing, or has anyone experience this before that would cause overflown text to become jumbled?

       

      Thanks in advance for any help/advice/suggestions!

       

      -Lloyd

        • 1. Re: [CS5][JS] Update TextFrame contents with overflow??
          [Jongware]-9BC6tI Level 4

          Yep -- been there, done that, seen it.

           

          It's caused by the way you add text and formatting to your text frame. Things like "line" don't work in an overset frame (because there is no frame to get the text width from). It seems other stuff get, well, not really "messed up", it's more like ID cannot properly access stuff that doesn't actually exist yet.

           

          I settled for the lo-tech solution of make the text frame way larger than absolutely necessary

          1 person found this helpful
          • 2. Re: [CS5][JS] Update TextFrame contents with overflow??
            lhanneman Level 1

            Thanks for the reply!

             

            Well, I don't know if this makes a difference or not, but the way I'm adding text is by creating a whole new text frame on the fly, adding all of my text/styles etc, then moving my text from the "temp" text frame into the appropriate frame to be updated. This was done so that if the text frame being updated is threaded/grouped with another frame, it would flow easier when adding the text.

             

            Making the textframe that needs to be updated larger isn't really an option, and I've tried increasing the size of the temporary text frame, but it appears that when I move the text into the final text frame, it still jumbles the overflow text. Any thoughts?

            • 3. Re: [CS5][JS] Update TextFrame contents with overflow??
              [Jongware]-9BC6tI Level 4

              Nope, sorry. Haven't seen that happen before ...

              • 4. Re: [CS5][JS] Update TextFrame contents with overflow??
                lhanneman Level 1

                so do you think if I captured the size/coordinates of the textframe to be updated, then increased the size to something really big, set the new text, then reset the size of the text frame back to what it was, that would work? I'm just not sure what a good work-around would be?

                • 5. Re: [CS5][JS] Update TextFrame contents with overflow??
                  [Jongware]-9BC6tI Level 4

                  Yes, that's exactly what I did. It's your "may be inside a group" remark that makes me wonder if that's feasible.

                   

                  Um. How about a workaround? Create a new (v. large) text frame, put your new text into that. Set its 'previousTextframe' to your original frame. Delete new text frame. (Again, don't know if it works with grouped items.)

                  • 6. Re: [CS5][JS] Update TextFrame contents with overflow??
                    John Hawkinson Level 5

                    Does calling the .recompose() method on the text frame help any? Just a shot in the dark...

                    • 7. Re: [CS5][JS] Update TextFrame contents with overflow??
                      lhanneman Level 1

                      Nope, tried that. Thanks for the input though!

                      • 8. Re: [CS5][JS] Update TextFrame contents with overflow??
                        lhanneman Level 1

                        What I've tried, and does work, is creating a "temp" text frame on the fly, and making it way bigger than it needs to be, and formatting my text in there. That way all of the text will for sure fit, then I can just move it into my original text frame. Do you guys see any performance issues with doing this (making the temp text frame huge)? Or should I be calculating about how big to make it so that the text will fit, but without making it way bigger than necessary?

                         

                        If so, how could I calulate/estimate it's size?

                        • 9. Re: [CS5][JS] Update TextFrame contents with overflow??
                          Mayhem SWE Level 2

                          What exactly do you mean by "jumbled and formatted differently"? Is the formatting random, or is your script changing the formatting inside the textframe but fails to process the overset text? If the latter I am guessing your script targets TextFrame.texts, TextFrame.paragraphs, TextFrame.lines, TextFrame.characters or similar in which case I would try to target TextFrame.parentStory.<whatever> instead.

                          • 10. Re: [CS5][JS] Update TextFrame contents with overflow??
                            LenZigante

                            I regret I'm having a similar problem & the answers I'm seeing aren't providing solutions.

                             

                            In my case, what I have is a large volume of unformatted text dumped into a text box awaiting mass formatting via my script which relies on Grep/Text Find & Change functions. How it's suppose to work is if specific text is selected within a text frame then only that text is formatted. If one or more text frames are selected then ALL the text in those text boxes is to be formatted INCLUDING overset text but (preferably) excluding text flowed into linked text boxes (this part I've not worked out yet). If nothing is selected then all text frames on the visible layers of the document are to be mass formatted (again this hasn't been fully worked out yet).

                             

                            Currently what is happening is that if text boxes are selected, ONLY the text visible within the text boxes has the formatting applied to it. Anything hidden in overset text remains untouched. Can anyone shed some light on where I'm going wrong & how to solve it?

                             

                            This is the function I've created thus far :

                             

                            function doFindReplace(searchTypeString /*t|g*/, doc/*obj - the document*/) {

                                // check if the default or specified document is open. If no document is provided, default document is assumed.

                                var theDoc = doc;

                                try{

                                    if( !(theDoc||(theDoc = app.activeDocument)) )

                                        { throw new Error("No document available."); }

                                    }

                                catch (e) {

                                    abort = true;

                                    alert( e.name + "\n" + e.message );

                                    return;

                                }

                             

                                // for every selected textual type item do the find & replace

                                var counter1 = 0;

                                do {

                                    try{

                                        // perform find & replace

                                        if (abort == false && (app.selection[counter1] instanceof TextFrame || app.selection[counter1] instanceof Text) ) { // If nothing in the script has previously returned an error, proceed to do search & replace on selected textual type things only

                                            switch ( searchTypeString) {

                                                case "t":

                                                if (theDoc.selection[counter1]) {

                                                    theDoc.selection[counter1].changeText();

                                                    }

                                                else {

                                                    theDoc.changeText();                  

                                                    }

                                                    break;

                                                case "g":

                                                if (theDoc.selection[counter1]) {

                                                    theDoc.selection[counter1].changeGrep();

                                                    }

                                                else {

                                                    theDoc.changeGrep();

                                                    }

                                                    break;

                                                    }

                                                }

                                            }

                                    catch (e) {

                                        abort = true;

                                        alert( e.name + "\n" + e.message );

                                        return;

                                    }

                                counter1++;

                                } while (counter1 < app.selection.length);

                            }

                            //

                            • 11. Re: [CS5][JS] Update TextFrame contents with overflow??
                              LenZigante Level 1

                              Just figured it out - I needed to include ".parentStory" within the "change" lines ( eg. theDoc.selection[counter1].parentStory.changeText(); ).

                              Although this doesn't address text flowed into other text frames or just those on visible layers, it does solve the partial formatting issue I was having.