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

How to get textrange each line start and end character cooridnates using extendscript?

Explorer ,
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.

 

Capture2.PNG

Please help.

TOPICS
Draw and design , How-to , Scripting

Views

231

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

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
...

Votes

Translate

Translate
Adobe
Guide ,
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;
}

 

femkeblanco_0-1707952981141.png

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 16, 2024 Feb 16, 2024

Copy link to clipboard

Copied

LATEST

Hi Femkeblanco,

 

It is working. Thanks for your help.

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