2
Explorer
,
/t5/illustrator-discussions/how-to-get-textrange-each-line-start-and-end-character-cooridnates-using-extendscript/td-p/14422468
Feb 14, 2024
Feb 14, 2024
Copy link to clipboard
Copied
Hi,
I need to get each lines start and end character cooridnates points in textrange(text frame) using extendscript.
Please help.
TOPICS
Draw and design
,
How-to
,
Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
1 Correct answer
Guide
,
Feb 14, 2024
Feb 14, 2024
Not extensively tested, and not tested with sizeable text. "ouput" is an array of the left-most and right-most characters. You can access their position properties.
// select 1 textFrame
var doc = app.activeDocument;
var frames = doc.selection[0];
var replica = frames.duplicate(frames, ElementPlacement.PLACEAFTER);
var item = replica.createOutline();
var objects = [];
for (var i = 0; i < item.pageItems.length; i++) {
objects.push(item.pageItems[i]);
}
item.remove();
var temp = [];
for (var
...
Explore related tutorials & articles
Guide
,
/t5/illustrator-discussions/how-to-get-textrange-each-line-start-and-end-character-cooridnates-using-extendscript/m-p/14423655#M397444
Feb 14, 2024
Feb 14, 2024
Copy link to clipboard
Copied
Not extensively tested, and not tested with sizeable text. "ouput" is an array of the left-most and right-most characters. You can access their position properties.
// select 1 textFrame
var doc = app.activeDocument;
var frames = doc.selection[0];
var replica = frames.duplicate(frames, ElementPlacement.PLACEAFTER);
var item = replica.createOutline();
var objects = [];
for (var i = 0; i < item.pageItems.length; i++) {
objects.push(item.pageItems[i]);
}
item.remove();
var temp = [];
for (var i = 0, counter = 1; i < objects.length; i += counter) {
counter = 1;
var row = [];
row.push(objects[i]);
for (var j = i + 1; j < objects.length; j++) {
if (horizontalOverlap(objects[i], objects[j])) {
row.push(objects[j]);
counter++;
}
}
temp.push(row);
}
function horizontalOverlap(obj1, obj2) {
var top1 = obj1.geometricBounds[1];
var bottom1 = obj1.geometricBounds[3];
var top2 = obj2.geometricBounds[1];
var bottom2 = obj2.geometricBounds[3];
return ((top1 >= top2 && bottom1 <= top2) ||
(top1 <= top2 && top1 >= bottom2));
}
// "ouput" is an array of the left-most and right-most chars
var output = [];
for (var i = 0; i < temp.length; i++) {
temp[i].sort(function (a, b) {return a.left - b.left});
output.push(temp[i][0]);
output.push(temp[i][temp[i].length - 1]);
}
// e.g. of using "ouput", marking the positions of its elements (with red dots)
for (var i = 0; i < output.length; i++) {
var d = 5;
var item = doc.pathItems.ellipse(
output[i].position[1] + 5/2, output[i].position[0] - d/2, d, d);
var color1 = new RGBColor;
color1.red = 255;
color1.green = color1.blue = 0;
item.stroked = false;
item.fillColor = color1;
}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Arunkumar25715058ufpl
AUTHOR
Explorer
,
LATEST
/t5/illustrator-discussions/how-to-get-textrange-each-line-start-and-end-character-cooridnates-using-extendscript/m-p/14426593#M397636
Feb 16, 2024
Feb 16, 2024
Copy link to clipboard
Copied
Hi Femkeblanco,
It is working. Thanks for your help.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

