Skip to main content
Inspiring
May 5, 2011
Question

[CS5 - js] problem reading words in paragraphs

  • May 5, 2011
  • 1 reply
  • 939 views

Hi All.

I try to get all the words in a paragraph

MyTextFrame.paragraphs.words

If I read the contents of any word:

for (c = 0; c < MyTextFrame.paragraphs.words.length; c++)
{
    currentWord = MyTextFrame.paragraphs.words.contents;

     ..

     ..

}

some words appears more then one time and other have less characters than the original

Someone can tell me why?

thanks

Ivan

This topic has been closed for replies.

1 reply

Muppet_Mark-QAl63s
Inspiring
May 5, 2011

Im not sure but this does do what I think you are expecting…

var doc = app.activeDocument; var tFrame = doc.textFrames[0]; var para = tFrame.paragraphs[0]; var words = para.words; alert(words.length) for (var i = 0; i < words.length; i++)      {           alert(words.contents)      }

fivanAuthor
Inspiring
May 5, 2011

Hi Mark.

I have tried your script.

In my document I have a textBox containing this string.

-     HK     Profondità sgambatura     da fianco a fondo abbottonato     (0197)     (0002)     (04)

Every single information is separated by TAB.

Your script, exactly like mine, reads 15 words and these are the found words:

-

-

HK

HK

Profondità

sgambatura

sgambatura

da

fianco

a

fondo

abbottonato

019

000

04

I expect twelve words, not fifteen

Just one "-" and "sgambatura" insted of two

"(0197)" or "0197" insted of "019"

and "0002" insted of "000"

Using this string:

a b c (d) “e”

Space between letters.

The script reads four words: a, b, ( , "e"

Using this string:

a b c d e

Space between letters, the result is what I expect: five words a,b,c,d and e

It's very hard for me to understand the way words are considered

Muppet_Mark-QAl63s
Inspiring
May 5, 2011

In your case I would not use illustrator's definition of word and go for splitting the para yourself…

var doc = app.activeDocument; var tFrame = doc.textFrames[0]; var para = tFrame.paragraphs[0].contents; var words = para.split('\t'); alert(words.length) for (var i = 0; i < words.length; i++)      {           alert(words)      }

This worked for me once I replaced the multi-space of this forum with where I think you had tabs in your post…