2

I need an Indesign script to add a irregular textframe (polygon) to page and add text content to it. I have so far this code. but it is a regular text frame.

       var doc = app.documents.add();

       var textFrame = doc.textFrames.add();

       textFrame.properties =

       {

        geometricBounds : [ 0,0,100,100 ],

        strokeWidth : 0,

        fillColor : "None",

        contents : "Hello World!"
       }

I can also add this polygon but I can't add text to it.

       var doc = app.documents.add();

       var polygon = doc.polygons.add();
       var points = [
       [100,100],
       [150,100],
       [200,200],
       [120,150],
       [100,100],

]
       
polygon.paths.item(0) = points;
        

thanks for your help!

Ali Haghighi
  • 143
  • 3
  • 11

1 Answers1

1

Not sure if this is an optimal way for your workflow but it can be done this clumsy way:

var doc = app.documents.add();

var polygon = doc.polygons.add();
var points = [
    [100,100],
    [150,100],
    [200,200],
    [120,150],
    // [100,100], // this point doesn't need, since a polygon is a closed path
];
polygon.paths[0].entirePath = points;

polygon.contentType = ContentType.TEXT_TYPE;    // convert the polygon into a text frame
var poly_textFrame = doc.textFrames.lastItem(); // get the last text frame
poly_textFrame.contents = 'Hello World!';       // change contents of the frame

The problem of this approach is that I'm not sure if the new text frame is always a last item within of the text frames collection. It needs to be tested in vivo.

Yuri Khristich
  • 13,448
  • 2
  • 8
  • 23