10 Replies Latest reply on Nov 20, 2014 10:30 AM by Kevin J Fagan

    Set Heights for all text frames in a document

    Kevin J Fagan

      Looking to do something seemingly simple. I want all text frames in my document to be the same height.

       

       

      Here is where I am at.

       

      app.activeDocument.textFrames.everyItem().height  = "2.3195 in";

       

      Note: I am working in InDesign CS5.

       

      Any help on where to go from here would be greatly appreciated.

        • 1. Re: Set Heights for all text frames in a document
          TᴀW Adobe Community Professional & MVP

          What makes you think a textFrame has a height property? It doesn't. It's

          height can be got like this:

           

          myHeight = myFrame.geometricBounds[2] - myFrame.geometricBounds[0];

           

          You probably need to loop through all textFrames in the document one by

          one, and change their geometricBounds.

           

          A better way to do it would be to use a textFrame's reframe() method --

          but it's a little complicated. geometricBounds are easier at first.

          Here's what the help has to say about them:

           

          TextFrame.geometricBounds

          Data Type: Array of Measurement Unit (Number or String)

          Adobe InDesign CS6 (8.0) Object Model

          The bounds of the TextFrame excluding the stroke width, in the format

          , which give the coordinates of the top-left and

          bottom-right corners of the bounding box.

           

          ---

           

          Just remember that you have to write all that array in one go. You can't

          set just a single element in the array: myFrame.geometricBounds[1] =

          3.1418 for example is not good.

          • 2. Re: Set Heights for all text frames in a document
            Kevin J Fagan Level 1

            ahhh... I knew could not be that easy. Ha!

             

            This makes sense. As I am clearly a .js novice this will take me some time. Gonna give it a shot.

            • 3. Re: Set Heights for all text frames in a document
              TᴀW Adobe Community Professional & MVP

              Well, it almost could be that easy. For instance, if you have a document

              with single (not facing) pages, and you want all text frames to be

              identical, you could do:

               

              app.activeDocument.textFrames.everyItem().geometricBounds = [50, 50,

              300, 300];

               

              which is similar to what your wrote, and that should work.

               

              But if you're looking to only adjust their height, but they have

              variable widths, or if you've got facing pages, then it's trickier.

              (Although the facing pages issue, with reframe() and the correct

              coordinate space, could be doable, not sure offhand.)

              • 4. Re: Set Heights for all text frames in a document
                Kevin J Fagan Level 1

                hmm...

                 

                app.activeDocument.textFrames.everyItem().geometricBounds = [50, 50,

                300, 300];

                 

                This would just cause all textFrames to be positioned at the coordinates[50, 50, 300, 300] on the page, right?



                here is my extremely poor attempt at what I think I am looking for (forgive me):


                myFrame = app.activeDocument.textFrames.everyItem()

                myHeight = myFrame.geometricBounds[2] - myFrame.geometricBounds[0];

                 

                for (var c = 0; c < myFrame.length; c++) {

                  myFrame[width = myHeight];

                };

                • 6. Re: Set Heights for all text frames in a document
                  Marc Autret Level 4

                  Or, in CS6 and later*:

                   

                  var NEW_HEIGHT = '2.3195 in';
                  
                  // MULTIPLE RESIZE() IN ONE STEP
                  // =============================
                  app.activeDocument.textFrames.everyItem().resize(
                  
                      // Target bounding box(es) -- Use OUTER_STROKE_BOUNDS if needed
                      // ---
                      [CoordinateSpaces.INNER_COORDINATES, BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS],
                  
                      // Reference point -- Here resize is performed relative to the top edge
                      // ---
                      AnchorPoint.TOP_CENTER_ANCHOR,
                      
                      // Absolute replacement
                      // ---
                      ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
                  
                      // [width, height] in points
                      // ---
                      [ResizeConstraints.KEEP_CURRENT_VALUE, +UnitValue(NEW_HEIGHT).as('pt')]
                      );
                  
                  

                   

                  * Might work in CS5.x too, but I seem to remember that CS4 has a bug when resize() targets a plural specifier whose receivers belong to multiple spreads.

                   

                  @+

                  Marc

                  • 7. Re: Set Heights for all text frames in a document
                    Laubender Adobe Community Professional & MVP

                    @Marc – yes, a quick test with InDesign CS4 v6.0.6 is throwing an error.

                    Rougly translated from my German version of the ESTK:

                    "With this value, at least one object would be displaced from the pasteboard."

                    ("Mit diesem Wert würde mindestens ein Objekt von der Montagefläche verdrängt.")


                    However, with CS5.5 the script is running fine on the same document.

                     

                    Uwe

                    • 8. Re: Set Heights for all text frames in a document
                      Marc Autret Level 4

                      Hi Uwe,

                       

                      Thank you for the clarification. So, my memory was not so bad ;-)

                       

                      CS4 does not properly handle the xxx.everyItem() entity in the scope of resizing tasks, although the resizeIndividually parameter is supposedly defaulted to true. The "object(s) would leave the pasteboard" error message sounds like "Hey dude, are you in resizing all these items as a whole? I have no room for that!" (To which I'd reply, "Hey, Indi, what a fool you are!")

                       

                      @+

                      Marc

                      • 9. Re: Set Heights for all text frames in a document
                        Kevin J Fagan Level 1

                        Hi all, just ran in ID CS5 and work PERFECTLY!!!!  Truly amazing!!! Thank you all so much for the help.

                        • 10. Re: Re: Set Heights for all text frames in a document
                          Kevin J Fagan Level 1

                          hmm... trying to set a specific width and height. Am I close?

                           

                          var NEW_HEIGHT = '4 in';  
                          var NEW_WIDTH = '4 in'; 
                            
                          // MULTIPLE RESIZE() IN ONE STEP  
                          // =============================  
                          app.activeDocument.textFrames.everyItem().resize(  
                            
                              // Target bounding box(es) -- Use OUTER_STROKE_BOUNDS if needed  
                              // ---  
                              [CoordinateSpaces.INNER_COORDINATES, BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS],  
                            
                              // Reference point -- Here resize is performed relative to the top edge  
                              // ---  
                              AnchorPoint.TOP_CENTER_ANCHOR,  
                                
                              // Absolute replacement  
                              // ---  
                              ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,  
                            
                              // [width, height] in points  
                              // ---  
                              [ResizeConstraints.KEEP_CURRENT_VALUE, +UnitValue(NEW_HEIGHT)+UnitValue(NEW_WIDTH).as('pt')]  
                              );