How can I find the longest line in an InDesign document?

Is there a script that locates the longest line in an InDesign document?

Hello

I area with Vamitul (Welcome back, long time no see) that the smaller Panel is fairly trivial.

Not sure what Vamitul what you were asking about the block of code on the forum.

I just want to reaffirm it as a loop will be several times faster than sort on the same short document.

#targetengine longestLine
var docLines = app.activeDocument.stories.everyItem().lines.everyItem ().getElements(),
    l = docLines.length,
    lineLength, longestLines = [],
    longestLineLength = 0,
    multi;
while(l--) {
    if ((lineLength = docLines[l].characters.length) >= longestLineLength) {
            if (lineLength === longestLineLength) longestLines.push(docLines[l]);
            else longestLines = [docLines[l]];
            longestLineLength = lineLength;
    }
}
multi = longestLines.length ;
if (multi == 1) longestLines[0].select();
else {
    var n = 0,
        w = new Window ('palette'),
        b1 = w.add('button', undefined, "Next"),
        b2 = w.add('button', undefined, "Previous");
    w.show();
    b1.onClick = function () {selct(1)};
    b2.onClick = function () {selct(-1)};
    function selct (next) {
        n = (n + multi + next) % multi;
        longestLines[n].select();
    }
}

Concerning

Trevor

Tags: InDesign

Similar Questions

Maybe you are looking for