Skip to main content
Inspiring
April 11, 2023
Question

when did words.length change? or what makes a word?

  • April 11, 2023
  • 3 replies
  • 1921 views

some of my old scripts broke, don't know when it happened, but basically "This.Was.Four.Words" that text object used to be 4 words and now it is considered 1. the period no longer defines words? but…

 

when you introduce a number like this, "This.Is.3.Words", then the period matters. "This.Is" is 1 word, "3" is another, and finally "Words" is another

 

i don't see the logic to this. does anyone know why this changed and how is it beneficial?

This topic has been closed for replies.

3 replies

m1b
Community Expert
Community Expert
April 14, 2023

I have posted a bug report. Please vote on it. It appears this problem may have been introduced while fixing another bug.

- Mark

CarlosCanto
Community Expert
Community Expert
April 14, 2023

Windows 11

 

Results: 2023 v27.3.1
"This.Was.Four.Words"  word count:1
"This.Is.3.Words"  word count:3
"I.WF05f.07.AB.000"  word count:4
"I.WF05f.AB.07.000"  word count:2

Results: 2022 v26.4.1
"This.Was.Four.Words"  word count:4
"This.Is.3.Words"  word count:4
"I.WF05f.07.AB.000"  word count:5
"I.WF05f.AB.07.000"  word count:5

Results: 2021 v25.3.1
"This.Was.Four.Words"  word count:4
"This.Is.3.Words"  word count:4
"I.WF05f.07.AB.000"  word count:5
"I.WF05f.AB.07.000"  word count:5

 

m1b
Community Expert
Community Expert
April 12, 2023

I don't have any answers, but for the sake of testing different versions/platforms of Illustrator I propose using this as a starting point:

// testing Illustrator's word division algorithm
(function () {

    var lines = [
        "This.Was.Four.Words",
        "This.Is.3.Words",
        "I.WF05f.07.AB.000",
        "I.WF05f.AB.07.000",

        // add more lines here if you want,
        // but don't change those above

    ],

        doc = app.activeDocument,
        tf = doc.textFrames.add(),
        results = '';

    tf.contents = lines.join('\n');

    for (var i = 0; i < lines.length; i++)
        results += '"' + lines[i] + '"  word count:' + tf.lines[i].words.length + '\n';

    alert('Results:\n' + results);

})();

 

Can anyone using older versions of Illustrator try the above script and share results? @femkeblanco?

 

Here's what I get on AI 27.4 MacOS 13.3.1:

"This.Was.Four.Words"  word count:1
"This.Is.3.Words"      word count:3
"I.WF05f.07.AB.000"    word count:4
"I.WF05f.AB.07.000"    word count:2

- Mark

m1b
Community Expert
Community Expert
April 12, 2023

Irrelevent side note: Indesign gives these results:

"This.Was.Four.Words"  word count:1
"This.Is.3.Words"      word count:1
"I.WF05f.07.AB.000"    word count:1
"I.WF05f.AB.07.000"    word count:1
"This is four words."  word count:4
femkeblanco
Legend
April 13, 2023

Sorry for the late reply.  I get the same result as Monika in CS6 on Windows. 

I've never thought about the definition of a "word" in AI, although I would have assumed it would be bound by whitespace. 

pixxxelschubser
Community Expert
Community Expert
April 11, 2023

Sorry, but your description is incomprehensible. Please explain in more detail what your script does.

 

  1. What is before in your document?
  2. What is after in your document?
  3. What happens (or doesn't happen) since your script is "broken".
  4. How well do you know scripting?
  5. How many lines of code does your script have?
  6. Can you post the relevant part of the code as plain text?
mecdosAuthor
Inspiring
April 11, 2023

i don't see how any of that is relevant, my script is over 2000 lines. i've been doing this for a while, i have succesful extensions for sale on the marketplace.

 

simplified question 

for textFrames[index].words, what consituted a "word" has changed. i was using the Words collections as a means to verify formats for internal code numbers (like "I.WF05f.07.AB.000") and changing/updating different parts of number, like counting, formatting, exporting related data etc.

 

before a textFrame with contents of "I.WF05f.07.AB.000" would have a word count of 5, but now it has a word coutn of 4. code like textFrame[index].words[4].contents = "001", is now out of range. 

 

but anyway, i know why my script doesn't work, i'm asking when did this change, what illustrator version do i need to revert to?

 

extra if anyone knows of a white paper on what is a word in a word collection because "I.WF05f.07.AB.000" and "I.WF05f.AB.07.000" have different word counts. so far what i gather is that a period doesn't create words, but a period between 1 letter and 1 number does. seems like a complicated algorythm with no benefit. 

pixxxelschubser
Community Expert
Community Expert
April 11, 2023

Ich antworte lieber in meiner Muttersprache. So fällt es mir leichter, eine adäquate unmissverständliche Antwort zu schreiben. Wir sind nur Benutzer wie du auch. Und wir wollen dir bei deinem aufgetretenen Problem helfen.

 

Ob bzw. wann etwas an der Kollektion "Wörter" geändert wurde … das weiß ich leider nicht.

 

Dennoch gibt es sicherlich eine Lösung für dein Problem.

Alle meine Fragen waren berechtigt.

Da ich deine Frage nicht verstanden habe, musste ich zuerst wissen, ob du Kenntnisse hast - oder nicht.

Ohne deinen Code zu sehen, weiß ich nicht was dein Code machen soll. Die Frage nach der Länge deines Scripts hatte nur eine Relevanz: Ein paar Dutzend Zeilen Code kann man problemlos im Forum posten und wir können sie auch problemlos testen. Bei mehreren Hundert Zeilen Code geht das über den Rahmen des Forums hinaus.

 

Dann bleiben noch die Fragen nach dem:

Was war vorher in deinem Dokument? und

Was ist hinterher in deinem Dokument? und

Was passiert (oder passiert nicht mehr) seitdem dein Script nicht mehr funktioniert?

 

Du suchst nach einer Lösung. Alle diese Fragen würden zur Lösungfindung beitragen.

 

So wie ich das sehe, hast du bisher die Kollektion "Wörter" für einen Zweck "missbraucht", für den sie nicht gedacht ist. Das hat wohl bisher funktioniert. Jetzt scheint es nicht mehr zu funktionieren. Habe ich dich soweit richtig verstanden?

 

Wenn ja, dann gibt es wahrscheinlich nur zwei Möglichkeiten:

1) Zurück zur Version 26 (dort scheint es noch zu funktionieren) oder

2) die wahrscheinlich besser geeigneteren Codevarianten zu verwenden:

 - Arbeiten mit Arrays aus deinem String oder

 - Anwenden von Regex auf deinen String

 

Für diese Varianten muss man aber genau wissen, was mit deinem Inhalt/String genau passieren soll.

z.B. erhältst du auf diesem Weg genau das erwünschte Ergebnis

Textframe [0] mit Inhalt: I.WF05f.AB.07.000

 

var Arr = app.activeDocument.textFrames[0].contents.split(".")
alert(Arr.length)

 

Ergebnis: 5