Skip navigation
Currently Being Moderated

Add points to text frame, possible?

Mar 21, 2010 7:29 PM

Is it possible to add a point to a text frame with a script?






  • Currently Being Moderated
    Mar 21, 2010 10:01 PM   in reply to Fred Goldman

    Hi Fred,


    Yes it is possible through indesign script.


    See below Adobe Indesign Sample script.



    //An InDesign CS4 JavaScript


    //Shows how to use the add path method.


    function main(){





    function mySetup(){

    var myDocument = app.documents.add();

    myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;

    myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

    myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

    var myPage = myDocument.pages.item(0);

    var myRectangle = myPage.rectangles.add();

    myRectangle.geometricBounds = [72, 72, 144, 144];

    var myOval = myPage.ovals.add();

    myOval.geometricBounds = [108, 108, 180, 180];


    function mySnippet(){

    var myRectangle = app.documents.item(0).pages.item(0).rectangles.item(0);

    var myOval = app.documents.item(0).pages.item(0).ovals.item(0);


    //Given a rectangle "myRectangle" and an Oval "myOval"...




    function myTeardown(){






    Mark as:
  • Currently Being Moderated
    Mar 22, 2010 3:18 AM   in reply to Fred Goldman

    Sure. A text frame is a geometric shape as any other; as far as InDesign is concerned, it's just a rectangle.


    All geometric shapes in InDesign consist of one or more paths -- they all have a property "paths" as Array. Each path contains a pathPoints array, and this is what you would manipulate to add a corner.


    Since you can't really be sure what the lower right corner is, this script does not change the pathPoints immediately. Rather, it copies the path, tries to find the corner (not sure if this is "the way" ), adds two points after that and moves these points around to make the inset.


    myRect = app.selection[0];
    myPath = myRect.paths[0];
    myPathPoints = myPath.entirePath;
    // Determine lower right -- not sure if it's always the same!
    corner = 0;
    for (a=1; a<myPathPoints.length; a++)
     if (myPathPoints[a][0] > myPathPoints[corner][0])
      corner = a;
     if (myPathPoints[a][1] > myPathPoints[corner][1])
      corner = a;
    // Add two point 'after' corner
    // Use old corner point as model
    p1 = [myPathPoints[corner][0], myPathPoints[corner][1]];
    p2 = [myPathPoints[corner][0], myPathPoints[corner][1]];
    myPathPoints.splice (corner+1,0, p1, p2);
    // Move x of original corner point
    myPathPoints[corner][0] -= 5;
    // Move x and y of new angle point
    p1[0] -= 5;
    p1[1] -= 5;
    // Move y of back-to-frame point
    p2[1] -= 5;
    // Put modified path back into object
    myPath.entirePath = myPathPoints;
    Mark as:
  • Currently Being Moderated
    Mar 22, 2010 2:06 PM   in reply to Fred Goldman

    You might be wondering, "why that workaround creating new p1 and p2's?". (Then again, you may be not. I'll continue, just in case.)


    Initially, I wrote this:


    myPathPoints.splice (corner+1,0, myPathPoints[corner], myPathPoints[corner]);


    to insert copies of the corner point --- and ... the script didnae work! Even though I did change all of the points' coordinates, it appeared they were always changed to the same value for each.


    For some reason I can never remember what sort of objects are duplicated, and under what circumstances, and of which only references are copied. In this particular case, it appears that ("magically") the newly added points are not only duplicates of that one point, but essentially point to the same point (if you get my, ehm, point). So changing the original corner changed all "three" instances (the quotes are because it seems it's only one instance); changing the "2nd" point changed it again, and so did changing the "3rd".


    The Moral of this entertaining exercise: if you think you are 'copying' stuff and weird things start to happen, try an implicit create-and-insert instead. It might save you some headaches if you are aware this might happen.

    Mark as:
  • Currently Being Moderated
    Mar 4, 2012 3:00 PM   in reply to [Jongware]

    Hi Jongware,


    I found this post using a search and was trying to modify the script to work for the other corners, the top left was easy just changing the > to < and the - to + but I am having problems with the top right and bottom left corners.


    I realize that a combination of the x and y coordinates of the diagonal cornners need to be used and have tried 2 paracetamol and some tiger balm but still no luck so I am now resorting to begging


    Would much appriciate help.



    Mark as:
  • Currently Being Moderated
    Mar 5, 2012 3:25 AM   in reply to Trevorׅ

    It's not as simple as "changing < to >"


    The geometric bounds are stored in this weird format: [top left bottom right] (it's 'weird' because usually one would use [left top right bottom], to get 2 coordinate pairs in the usual format (x,y); I see this exact same notation in other Adobe software as well, so I think it's just a tradition of theirs).


    My script first checks the "top" value [0], then the "left' value [1]. For other corners, you have to check another combination of top, left, bottom, and/or right, and probably fiddle with the < and > as well, that's one thing I NEVER get right first time.

    Mark as:
  • Currently Being Moderated
    Mar 5, 2012 3:28 AM   in reply to [Jongware]

    Ah, sorry, I see that my original script doesn't use geometricBounds. The [0] and [1] are plain old (x,y) pairs. I guess you have to try less-than and greater-than after all.

    Mark as:
  • Currently Being Moderated
    Mar 5, 2012 6:33 AM   in reply to [Jongware]

    Thanks for the feedback


    I decided that it would be easier to go for using geometric bounds and as I don't need to check which corner is the real right

    I came up with the following code which is easy to change according to the desired corner.



    myRect = app.selection[0];
    myRectGeo = myRect.geometricBounds;
    myTempRect = myRect.rectangles.add();
    myTempRect.geometricBounds = [myRectGeo[0]+(myRectGeo[2]-myRectGeo[0])/2, myRectGeo[1]+(myRectGeo[3]-myRectGeo[1])/2,
    myRectGeo[2], myRectGeo[3]];
    myTempRect.subtractPath (myRect);
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points