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

How to find the top left point of tilted area text

Explorer ,
Feb 24, 2021 Feb 24, 2021

Copy link to clipboard

Copied

Hello, I hope somebody can help 🙂
How can I define the top-left point in a TextType.AREATEXT, when it's tilted?

Screenshot 2021-02-24 at 16.16.49.png

TOPICS
Scripting , Type

Views

455

Translate

Translate

Report

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 , Feb 24, 2021 Feb 24, 2021

the bounding box of an area text item is actually a pathItem, you can query any of their anchors position. 

Anchor[0] is not always the top/left most anchor though, it depends on how the area text was drawn. It's not always clockwise either. So any of the four anchors could be the one you're looking for.

one way to find out the top/left anchor even if it is upside down is to convert a copy of the item to PointText, then find out it's anchor position and compare to the corner anchors for proximit

...

Votes

Translate

Translate
Adobe
Community Expert ,
Feb 24, 2021 Feb 24, 2021

Copy link to clipboard

Copied

Hi,

You can use geometricBounds property to get to top-left coordinate. Select the object and run the following snippet

 

var a = app.selection[0];
var _geometricBounds = a.geometricBounds;
alert(_geometricBounds);
alert("Top -> " + _geometricBounds[0]);
alert("Left -> " + _geometricBounds[1]);

 

Best regards

Votes

Translate

Translate

Report

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
Explorer ,
Feb 24, 2021 Feb 24, 2021

Copy link to clipboard

Copied

Thanks, Charu,  I already tried it, but when a text is tiled, than geometricBounds are Bounding Box Bounds

Votes

Translate

Translate

Report

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
Valorous Hero ,
Feb 24, 2021 Feb 24, 2021

Copy link to clipboard

Copied

The images and area texts get a special 'tag' put on them by Illustrator when certain rotation methods are used.

Silly-V_0-1614183221645.png

 

When the item is rotated using the Rotate tool or rotate tool via menu-item (Transform > Scale, etc), the tag called "BBAccumRotation" is added with a value which you can use to calculate the point and know which one (top, bottom..) it is.
You can get this information using these scripting commands:

#target illustrator
function test () {
	/** @TyPe {Document} */
	var doc = app.activeDocument;
	/** @TyPe {TextFrame} */
	var s = doc.selection[0];
	var tags = s.tags;
	var tagName = tags[0].name;
	var tagValue = tags[0].value;
	alert("Name: " + tagName + "\nValue: " + tagValue);
};
test();

 

Silly-V_1-1614183892014.png

 

Note that an area type box which is rotated using the bounding box handles does not produce such a tag and all the text inside maintains its orientation.

Silly-V_2-1614184003336.png

 

The UI you see here with Tag Name and Value is a ScriptUI dialog I made which uses the same functions as in the example, but it writes them out in a list.

Votes

Translate

Translate

Report

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
Explorer ,
Feb 24, 2021 Feb 24, 2021

Copy link to clipboard

Copied

Thank you, Vasily,  I believe it can work 🙂

Votes

Translate

Translate

Report

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 ,
Feb 24, 2021 Feb 24, 2021

Copy link to clipboard

Copied

And I believe that the rotation number is in radians so another calculation will be required.

Votes

Translate

Translate

Report

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
Valorous Hero ,
Feb 24, 2021 Feb 24, 2021

Copy link to clipboard

Copied

Yes, it is needed just to know what index it is, so you'd un-rotate the item using the math and see which point is the left-top-est. If done with math only and not rotating the object back then you'd have the coordinate set right there from the actual point. But if getting the top-left point is done via real object rotation to skip on the math, it would have to be rotated back the same amount to get the real coordinates.

 

Votes

Translate

Translate

Report

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 ,
Feb 24, 2021 Feb 24, 2021

Copy link to clipboard

Copied

the bounding box of an area text item is actually a pathItem, you can query any of their anchors position. 

Anchor[0] is not always the top/left most anchor though, it depends on how the area text was drawn. It's not always clockwise either. So any of the four anchors could be the one you're looking for.

one way to find out the top/left anchor even if it is upside down is to convert a copy of the item to PointText, then find out it's anchor position and compare to the corner anchors for proximity.

 

var idoc = app.activeDocument;
var sel = idoc.selection[0];

var points = sel.textPath.pathPoints;

for (var a=0; a<points.length; a++) {
    alert(points[a].anchor);
}

 

Votes

Translate

Translate

Report

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
Valorous Hero ,
Feb 24, 2021 Feb 24, 2021

Copy link to clipboard

Copied

:light_bulb:

Votes

Translate

Translate

Report

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
Explorer ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

Thank you Carlos. It was just what I needed. Simple and easy. 🙂

Votes

Translate

Translate

Report

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
Guide ,
Feb 24, 2021 Feb 24, 2021

Copy link to clipboard

Copied

 

// calculate angle of rotation
var x = Math.acos( activeDocument.selection[0].matrix.mValueA ) / Math.PI  *  180;
if (activeDocument.selection[0].matrix.mValueB < 0) {
    x = x * (-1);
}
var points = [];
for (var i = 0; i < selection[0].textPath.pathPoints.length; i++) {
    points.push(selection[0].textPath.pathPoints[i]);
}
// depending on angle, point sought is either top-most, left-most, bottom-most or right-most
if (x > 0 && x <= 90) {
    points.sort(function(a, b) {return a.anchor[0] - b.anchor[0];})
} else if (x > 90 && x <= 180) {
    points.sort(function(a, b) {return a.anchor[1] - b.anchor[1];})
} else if (x > -180 && x <= -90) {
    points.sort(function(a, b) {return b.anchor[0] - a.anchor[0];})
} else {
    points.sort(function(a, b) {return b.anchor[1] - a.anchor[1];})
}
alert( points[0].anchor );

 

Votes

Translate

Translate

Report

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
Explorer ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

LATEST

Thank you, it also can work, but I think, that Carlos have the easier solution to my issue 🙂

Votes

Translate

Translate

Report

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