3 Replies Latest reply on May 30, 2012 4:30 AM by Velprakash

    Resize a text frame, depending on the amount of imported text ...

    Marcos Suárez

      I have read in some post something about it, but do not remember where ...

      I need a script that allows me to resize a text frame, only vertically, depending on the amount of imported text ...

      Is this possible?

       

      Thanks in advance...!!!

        • 1. Re: Resize a text frame, depending on the amount of imported text ...
          -hans- Level 4

          Hi,

           

          may be it's not the fastest ;-), but could be one approach ...

           

          Edit: Have to say it doesn't deal with textflows of multiple Textframes ...

           

           

           

          var myLineHeight = 3.573 // default mm in my case

           

          getOverflowState(app.selection[0]) //assuming one textframe in selection

           

          function getOverflowState(aTextFrame){

              var theOverflow = aTextFrame.overflows;

              switch(theOverflow){

          case false:

          while(aTextFrame.overflows == false){

              var theBounds = aTextFrame.visibleBounds;

          aTextFrame.visibleBounds = [theBounds[0], theBounds[1], theBounds[2] - myLineHeight, theBounds[3]];

              }

          getOverflowState(aTextFrame);

          break;

          default: setTfHeight(aTextFrame);

          break;

                  }

           

              }

           

           

          function setTfHeight(setHeightTextFrame){

           

              while(setHeightTextFrame.overflows == true){

                      var tfBounds = setHeightTextFrame.visibleBounds;

          setHeightTextFrame.visibleBounds = [tfBounds[0], tfBounds[1], tfBounds[2] + myLineHeight, tfBounds[3]];

                  }

                  }

          1 person found this helpful
          • 2. Re: Resize a text frame, depending on the amount of imported text ...
            Velprakash

            Hi Marcos Suárez,

                                  If u've textframe's overflow and some textframe's empty, then use the below codes to avoid the overflow...


            doc=app.activeDocument;

            pag=doc.pages.length;

            var count=1;

            for(var i=0;i<doc.pages.length;i++)

            {

                for(var j=0;j<doc.pages[i].textFrames.length;j++)

                {

                    txt=doc.pages[i].textFrames[j];

                    if(count<pag)

                    {

                        txt.nextTextFrame=doc.pages[(i+1)].textFrames[j];

                        count++;

                        }

                    }

                }

             

            Thanks and regards,

            Vel.

            • 3. Re: Resize a text frame, depending on the amount of imported text ...
              Velprakash Level 1

              Hi,

                 Make the modification as below... The changes are mentioned in bold... Hope it helps.

               

              var myDocument = app.activeDocument;

              gb=myDocument.pages[0].textFrames[0].geometricBounds;

              var myRegExp = ".+";

              app.findGrepPreferences = NothingEnum.nothing;

              app.changeGrepPreferences = NothingEnum.nothing;

              app.findGrepPreferences.appliedParagraphStyle = "Paragraph Style 3";

              app.findGrepPreferences.findWhat = myRegExp;

              var myFoundItems = myDocument.findGrep(true);

               

              if(myFoundItems.length != 0){

                    for(var myCounter = 0; myCounter < myFoundItems.length; myCounter ++){

                        myFoundItem = myFoundItems[myCounter];

                        myX1 = myFoundItem.characters.item(0).horizontalOffset;

                        myY1 = myFoundItem.characters.item(0).baseline;

                        myX2 = myX1 + 50;

                        myY2 = myY1 + 50;

                        

                          app.selection = myFoundItem;

                              app.cut();

                          myTextFrame = myDocument.textFrames.add();

                          myTextFrame.geometricBounds = [myY1, gb[1], myY2, gb[3]];

                          app.selection = myTextFrame.insertionPoints[0];

                              app.paste(); // Pega el texto del caso encontrado

                          //myTextFrame.applyObjectStyle(app.activeDocument.objectStyles.item("Paragraph Style 3"), true);           

                          myTextFrame.fit(FitOptions.FRAME_TO_CONTENT);

                  }        

              }

               

              Regards,

              Vel.