Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Add points to text frame, possible?

Enthusiast ,
Mar 21, 2010 Mar 21, 2010

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

Before:

Before.GIF

After:

After.GIF

TOPICS
Scripting
3.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 22, 2010 Mar 22, 2010

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

...
Translate
Engaged ,
Mar 21, 2010 Mar 21, 2010

Hi Fred,

Yes it is possible through indesign script.

See below Adobe Indesign Sample script.

//AddPath.jsx

//An InDesign CS4 JavaScript

//

//Shows how to use the add path method.

main();

function main(){

mySetup();

mySnippet();

myTeardown();

}

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);

//<fragment>

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

myRectangle.addPath(myOval);

//</fragment>

}

function myTeardown(){

}

Shonky

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 22, 2010 Mar 22, 2010

Hi Shonky,

I noticed this way. But you have to have multiple shapes first. I was wondering if it was possible without having to draw a new shape.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2010 Mar 22, 2010

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[0] > myPathPoints[corner][0])
  corner = a;
if (myPathPoints
[1] > myPathPoints[corner][1])
  corner = a;
}
// Add two point 'after' corner
// Use old corner point a...












Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 22, 2010 Mar 22, 2010

Thanks Jongware, this is what I was looking for. I was looking for points on text frame, I didn't realize points existed on a path.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2010 Mar 22, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 04, 2012 Mar 04, 2012

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.

Trevor

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2012 Mar 05, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2012 Mar 05, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 05, 2012 Mar 05, 2012
LATEST

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines