8 Replies Latest reply on Oct 14, 2016 12:46 AM by Laubender

    Help with overset text script?

    cbishop01 Level 2

      Hi i just found this script i believe that it was by Laubender. Which i've been using for a while now and i love it. Makes it easier to see where the text frames with overset text are.  My Question is.  How would i alter this to Get rid of the Magenta FIll color(maybe with the original text box color before the Script ran?) after the overset text is corrected

       

        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;   
        app.doScript  
          (  
          detectOverflowingTextFrames,  
          ScriptLanguage.JAVASCRIPT,  
          [],  
          UndoModes.ENTIRE_SCRIPT,  
          "Detect Overflowing TextFrames | SCRIPT"   
          );  
          
        function detectOverflowingTextFrames() {    
        var storyArray = app.documents[0].stories.everyItem().getElements();  
        var storyArrayLength = storyArray.length;  
      
       // A loop through all the stories of the document:  
        for(var n=0;n<storyArray.length;n++)  
        {  
          // The condition should be clear.  
          // However, there is one rare case where overflows is false,  
          // but the text frame is showing a red + sign:  
          // If a footnote text overflows in the last frame of a threaded story.  
           
          if(storyArray[n].overflows)  
          {  
            // TextContainers could be textFrames and textPaths !!  
            var textContainersArray = storyArray[n].textContainers;  
            var lastTextContainer = textContainersArray[textContainersArray.length-1];  
             
            // A function call to the last text frame, if its story overflows:  
            doSomethingWithTextContainers(lastTextContainer);  
           };  
          
        }  
          
        function doSomethingWithTextContainers(/*textFrame or textPath*/textContainer)  
        {  
          if(textContainer.constructor.name == "TextFrame") // Could be text on path as well  
          {  
            // Here your code that is changing the size of your frame  
            // In my example code here it will only fill the frame with color Magenta:  
            textContainer.fillColor = "Magenta";  
            // If you want to move the text frame, consider to unlock it first, if it is locked.  
          }  
          if(textContainer.constructor.name == "TextPath")  
          {  
            // Here your code, if text on a path should overflow.  
            // Depending on the pageItem that holds the path, the parent should be the pageItem you are interested in.  
            // Usually a graphicLine or a polygon. Could also be an oval, a rectangle or even a textFrame.  
             textContainer.parent.fillColor = "Magenta";  
             textContainer.parent.strokeColor = "Magenta";  
          }  
         
        }  
          
      };  
      

       

      Thank you

      Chris bishop

        • 1. Re: Help with overset text script?
          tpk1982 Level 4

          Not a big deal.. just comment those lines like below

           

          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;   
            app.doScript   
              (   
              detectOverflowingTextFrames,   
              ScriptLanguage.JAVASCRIPT,   
              [],   
              UndoModes.ENTIRE_SCRIPT,   
              "Detect Overflowing TextFrames | SCRIPT"   
              );   
               
            function detectOverflowingTextFrames() {     
            var storyArray = app.documents[0].stories.everyItem().getElements();   
            var storyArrayLength = storyArray.length;   
          
          // A loop through all the stories of the document:   
            for(var n=0;n<storyArray.length;n++)   
            {   
              // The condition should be clear.   
              // However, there is one rare case where overflows is false,   
              // but the text frame is showing a red + sign:   
              // If a footnote text overflows in the last frame of a threaded story.   
               
              if(storyArray[n].overflows)   
              {   
                // TextContainers could be textFrames and textPaths !!   
                var textContainersArray = storyArray[n].textContainers;   
                var lastTextContainer = textContainersArray[textContainersArray.length-1];   
                 
                // A function call to the last text frame, if its story overflows:   
                doSomethingWithTextContainers(lastTextContainer);   
              };   
               
            }   
               
            function doSomethingWithTextContainers(/*textFrame or textPath*/textContainer)   
            {   
              if(textContainer.constructor.name == "TextFrame") // Could be text on path as well   
              {   
                // Here your code that is changing the size of your frame   
                // In my example code here it will only fill the frame with color Magenta:   
          //~      textContainer.fillColor = "Magenta";   
                      alert("Overset found")
                // If you want to move the text frame, consider to unlock it first, if it is locked.   
              }   
              if(textContainer.constructor.name == "TextPath")   
              {   
                // Here your code, if text on a path should overflow.   
                // Depending on the pageItem that holds the path, the parent should be the pageItem you are interested in.   
                // Usually a graphicLine or a polygon. Could also be an oval, a rectangle or even a textFrame.   
          //~        textContainer.parent.fillColor = "Magenta";   
          //~        textContainer.parent.strokeColor = "Magenta";   
                      alert("Overset found")
          
          
              }   
             
            }   
               
          };
          
          1 person found this helpful
          • 2. Re: Help with overset text script?
            cbishop01 Level 2

            Hi tpk1982.  Sorry I meant that i wanted to keep the magenta fill until i Fix the Overset Text.  This Just alerts me that there are Overset text.  I would still like it to Fill the Text box like the first script did.  And after i Correct the Overset text i would then like the magenta I would like the fill to Go back to what it was before it detected the Overset.  Or at least go to a Fill of none.

            • 3. Re: Help with overset text script?
              Skemicle Level 3

              As long as you don't create a new text container to fix the overset; the following script should work for you.

              //Scripted by ?Laubender?
              //modified by Skemicle
              if (parseFloat(app.version) < 6)
              main();
              else
              app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Splice Image Along Path");
              function main() {
                  var doc = app.activeDocument;
                  var stories = doc.stories;
                  for(s=0;s<stories.length;s++){
                      var lastFrame = stories[s].textContainers[stories[s].textContainers.length - 1];
                      if(stories[s].overflows){
                          if(lastFrame.constructor.name == "TextFrame"){
                              lastFrame.fillColor = "Magenta";
                          }if(lastFrame.constructor.name == "TextPath"){
                              lastFrame.parent.fillColor = lastFrame.parent.strokeColor = "Magenta";
                          }
                      }else{
                          if(lastFrame.constructor.name == "TextFrame"){
                              if(lastFrame.fillColor.name == "Magenta"){
                                  lastFrame.fillColor = "None";
                              }
                          }if(lastFrame.constructor.name == "TextPath"){
                              if(lastFrame.parent.fillColor.name == "Magenta" && lastFrame.parent.strokeColor.name == "Magenta"){
                                  lastFrame.parent.fillColor = lastFrame.parent.strokeColor = "None"
                              }
                          }
                      }
                      
                  }
              }
              
              1 person found this helpful
              • 4. Re: Help with overset text script?
                tpk1982 Level 4

                Sorry Chris, I misunderstood..Skemicle script working fine

                • 5. Re: Help with overset text script?
                  cbishop01 Level 2

                  No problem i was probably explaining it wrong.   I just appreciate everyone's help.   I'll test this and get back to you guys.

                  • 6. Re: Help with overset text script?
                    cbishop01 Level 2

                    Thank you.  This does work great.  Is there a way for it to automatically detect that the Text is fitting so i dont have to run the script twice to get rid of the Magenta?  

                    • 7. Re: Help with overset text script?
                      cbishop01 Level 2

                      Never mind i added a event listener "afterSelectionChanged" and its works like i'm wanting.  Thank you guys agin.

                      • 8. Re: Help with overset text script?
                        Laubender Adobe Community Professional & MVP

                        Hi Chris,

                        indeed the code you posted with your question was written by me.

                        The last weeks I was unable to visit the forums much so I couldn't answer.

                         

                        Don't forget InDesign's preflight function.


                        Detecting overset text frames is quite easy and you could access the overset ones by simply clicking the listed page name. My script was thought as a utility to do something with the overset text frame: Make it larger so text could fit in, add another frame to the story etc.pp. The function named doSomethingWithTextContainers() gave only a hint, not a solution.

                         

                        Regards,
                        Uwe