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

alert if the document contains overset text warning

Community Beginner ,
Feb 18, 2023 Feb 18, 2023

Copy link to clipboard

Copied

var doc = app.activeDocument;
var textFrames = doc.textFrames;
var numTextFrames = textFrames.length; for (var i = 0; i < numTextFrames; i++) { var tf = textFrames[i]; if (tf.kind == TextType.AREATEXT && tf.textPath.contents.length > 0 && tf.textPath.overflows) { alert("Overset text detected in text frame " + (i+1)); } }

can anyone here help me on this!

This returns error

or any other way to alert

 

TOPICS
Scripting

Views

5.2K

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 25, 2023 Feb 25, 2023

Try this

var doc = app.activeDocument;
var textFrames = doc.textFrames;
var numTextFrames = textFrames.length;
for (var i = 0; i < numTextFrames; i++) {
    var tf = textFrames[i];
    if (tf.kind == TextType.AREATEXT &&
        tf.contents.length > 0 &&
        overflows(tf)) {
            alert("Overset text detected in text frame " + (i + 1));
            // tf.selected = true;
    }
}

function overflows(tf) {
    var lastLine = tf.lines[tf.lines.length - 1];
    var textRange1 = lastLine.con
...

Votes

Translate

Translate
Adobe
Community Beginner ,
Nov 15, 2023 Nov 15, 2023

Copy link to clipboard

Copied

Sorry, I wanted to reply to @femkeblanco 

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 Beginner ,
Nov 15, 2023 Nov 15, 2023

Copy link to clipboard

Copied

LATEST

My previous code has a flaw because if one paragraph does not fit in a line and is wrapped to next lines, lines will be added to the textFrame.lines without being any newline character in the original text. The solution is to first count characters of all lines as before; then removing every carriage return in the full text and counting the remaining charactes in it; then comparing two numbers.
Note that as far as I have tested, Illustrator  uses carriage return (\r) to separate paragraphs. I use Illustrator on Windows 10. I used a regular expression to remove the carriage return characters.
Updated version of my code:

function is_text_overflow(text){
    var char_count_lines = 0;
    var text_without_cr = text.textRange.contents.replace(/\r/g,"");

    for(var i = 0; i < text.lines.length; i++)
        char_count_lines += text.lines[i].contents.length;        

    return text_without_cr.length != char_count_lines;        
}



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