Skip to main content
Inspiring
September 12, 2012
Question

How to find Shape of the textframe.

  • September 12, 2012
  • 3 replies
  • 2214 views

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.

This topic has been closed for replies.

3 replies

Inspiring
June 27, 2015

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;

      

        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;

  

};

Marc Autret
Legend
September 12, 2012

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;

    with( tf.duplicate() )

        {

        convertShape(ConvertShapeOptions);

        t = paths[0].entirePath.toSource();

        remove();

        if( t == ep ) break;

        }

    }

alert( 0 <= i ?

    ("The textframe's shape is: " + CSO):

    ("Unable to detect the shape")

    );

@+

Marc

Known Participant
September 12, 2012

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

vDeepakAuthor
Inspiring
September 12, 2012

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.

Inspiring
September 12, 2012

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.pointType ); // PLAIN or SMOOTH and so on…

   

};