1 Reply Latest reply on Oct 18, 2011 1:21 PM by John Hawkinson

    Placing textFrame below Previous named textFrame

    swingcarlos

      Hi,

       

      I have several textframes that need to be placed one on top of each other.

      How do I go about placing a new frame whose dimensions(WxH) are known to just below the bottom of the previous frame.

       

      I'm getting the previous frame correctly using:

      prevFrame = myDocument.textFrames.item("A");

      var bottom = prevFrame.visibleBounds[2];

       

      I'm just not convinced that getting bottom/y2 this way is correct.  The values that are coming

      out of this do not come close to the expected values.

       

      1) How do I get the bottom frame so I can plug it into the new frame creation which uses:

      bounds[0] = bottom + spacer;

      bounds[2] = bounds[0] + width;

      tmpFrame.geometricBounds = bounds;    

       

      2) Would you use a different method of assigning width/height and then calling a 'move' function?

       

       

      Thanks for any help.

      Carlos

        • 1. Re: Placing textFrame below Previous named textFrame
          John Hawkinson Level 5

          Hi, Carlos.

           

          If the values from your visibleBounds array do not match what you see on the rulers, then something is wrong. Perhaps you have selected the wrong frame.

          var bottom = prevFrame.visibleBounds[2];
          

           

          I'm just not convinced that getting bottom/y2 this way is correct.  The values that are coming

          out of this do not come close to the expected values.

          I will say, I always find the bounds arrays horribly confusing and I use these helper functions:

           

           

          // fromBounds(gB) and toBounds(obj):                                        
          // Helper functions for dealing with InDesign's geomericBounds and          
          // visibleBounds properties. fromBounds() returns a JavaScript Object       
          // with y1/x1/y2/x2 properties for easy referencing, and toBounds converts  
          // it back to an array with the proper order. The intent here is to avoid   
          // scripts having to keep track of the ordering of fields.                  
          // Also return width/height properties, though they ought to be             
          // readonly (and aren't: xxx).                                              
          // Example usage: {                                                         
          //   var s = app.selection[0];                                              
          //   var sb = fromBounds(s.geometricBounds);                                
          //   $.writeln("(x1,y1) of selection are ("+sb.x1+','+sb.y1+")");           
          //   sb.x2 = sb.x2+sb.width;       // double the width (in our copy)    
          //   s.geometricBounds = toBounds(sb); // assign it for real                
          //  }                                                                       
          function fromBounds(gB) {
          
          
          return { y1: gB[0], x1: gB[1], y2: gB[2], x2: gB[3],
          
          
          height: gB[2]-gB[0], width: gB[3]-gB[1]};
          
          }
          function toBounds(obj) {
          
          
          return [ obj.y1, obj.x1, obj.y2, obj.x2 ];
          
          }
          

           

          That way, I you can just write:

           

          var bottom = fromBounds(prevFrame.visibleBounds).y2;

           

          But I suspect you have the wrong frame. Does app.select(prevFrame); cause the correct frame to be selected?