6 Replies Latest reply on Jun 27, 2015 4:51 PM by McShaman

    How to find Shape of the textframe.

    vDeepak Level 1

      Hello there....

       

      I have three textframes with different shapes. One is regular rectangular frame, other is oval and last one is triangular textframe.

       

      I want to find the shape of the text frame. Do anyone know how to find the shape of the textframe?

       

      Thanks in advance.

        • 1. Re: How to find Shape of the textframe.
          love_all Level 1

          HI vDeepak,

           

          Try This.....

           

          var select = app.selection[0].constructor.name;

          alert(select);

           

           

          I hope this is what u r asking for general frames

           

          And specificly I think we cant catch the textframe shape, since it is already a text container

           

          Regards,

          love_all

          • 2. Re: How to find Shape of the textframe.
            vDeepak Level 1

            Hi love_all,

             

            No. Unable to get actual shape of the frame. This alert is giving me as "TextFrame". Is it really impossible to get shape of the textframe? Because when oval or polygon is assigned text, its constructor.name gies textframe.

             

            Thanks.

            • 3. Re: How to find Shape of the textframe.
              Muppet Mark Level 5

              I would suspect that you are going to have to analyze the pathPoint collection and do a little math deduction…

              #target indesign
              
              var doc = app.activeDocument;
              
              var p = doc.textFrames.firstItem().paths.firstItem().pathPoints; // The containing path?
              
              $.writeln( p.length ); // Count
              
              for ( var i = 0; i < p.length; i++ ) {
                  
                  $.writeln( p[i].pointType ); // PLAIN or SMOOTH and so on…
                  
              };
              
              • 4. Re: How to find Shape of the textframe.
                [Jongware] Most Valuable Participant

                Muppet Mark wrote:

                 

                I would suspect that you are going to have to analyze the pathPoint collection and do a little math deduction…

                 

                A few observations on that:

                 

                All text frames with three points are triangular. Except when two points overlap, of course. Oh, and one of the points lies exactly on the line between the two other points (at its most extreme, that is the same as the other exception; the maths don't care).

                 

                All rectangles have four points but not all text frames with four points are rectangles. That's only true for p1..p4 if for all p(n)-p((n+1) mod 4) either their x coordinate OR their y coordinate is the same. This condition should be reversed for all subsequent points; and, again, points may not coincide nor fall on the path between two other points.

                 

                Is a 45 degrees rotated text frame still a valid rectangle?

                 

                Ovals ... now there is a challenge. An oval is just a circle with uneven horizontal and vertical axes, and thus its mathematical description is straightforward. Alas: InDesign does not really draw accurate ovals (nor circles, by the way). It uses Bezier curves that approximate them, and I have no idea how accurate that approximation is. You need to know that to be able to differentiate between 'a regular InDesign "oval"' and 'any shape with lots of bezier curves'.

                 

                If all you have is three text frames, one of which is a rectangle, the other a triangle, and the third an oval, these tests are all you need. If you may have *any* sort of text frame and want to know the 'best match' shape, you are in heaps of trouble -- what about a pentagon or a hexagon?

                • 5. Re: How to find Shape of the textframe.
                  Marc Autret Level 4

                  Hi,

                   

                  Maybe you can temporarily convert a duplicate of the textframe to the three different shapes, and then compare the entire path. In other words:

                   

                   

                  var CSO = ['OVAL','RECTANGLE','TRIANGLE'];
                  
                  var tf = app.selection[0], // assuming your text frame is selected
                      ep = tf.paths[0].entirePath.toSource(),
                      i = CSO.length,
                      k, t;
                  
                  while( i-- )
                      {
                      k = 'CONVERT_TO_'+CSO[i];
                      with( tf.duplicate() )
                          {
                          convertShape(ConvertShapeOptions[k]);
                          t = paths[0].entirePath.toSource();
                          remove();
                          if( t == ep ) break;
                          }
                      }
                  
                  alert( 0 <= i ?
                      ("The textframe's shape is: " + CSO[i]):
                      ("Unable to detect the shape")
                      );
                  

                   

                   

                  @+

                  Marc

                  • 6. Re: How to find Shape of the textframe.
                    McShaman Level 1

                    Maybe try something like this?

                     

                    var isTextFrameRectangle = function( obj ) {
                       
                        var points,
                            point,
                            adjIndex,
                            adjPoint,
                            axis,
                            i,
                            length;
                       
                        if( ! ( obj instanceof TextFrame ) ) {
                            return false;
                        }
                       
                        points = obj.paths.firstItem().pathPoints;
                       
                        if( ( length = points.length ) != 4 ) {
                            return false;
                        }
                       
                        for( i = 0; i < length; i++ ) {
                           
                            point = points[i];
                           
                            if( i == length - 1 ) {
                                adjIndex = 0;
                            } else {
                                adjIndex = i + 1;
                            }
                           
                            adjPoint = points[ adjIndex ];
                            axis = i % 2;
                           
                            if( point.anchor[ axis ] != adjPoint.anchor[ axis ] ) {
                                return false
                            }
                           
                        }
                       
                        return true;
                       
                    };