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

[CS5 - js] problem reading words in paragraphs

Explorer ,
May 05, 2011 May 05, 2011

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

TOPICS
Scripting
911
Translate
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
Adobe
Guide ,
May 05, 2011 May 05, 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)      }

Translate
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 ,
May 05, 2011 May 05, 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

Translate
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
Guide ,
May 05, 2011 May 05, 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…

Translate
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 ,
May 09, 2011 May 09, 2011

My Goal is to apply different characterstyle to any informations separated by tabs.

The only way I have found is read every character and checking the index. If i know the index of every tab I can apply the right character style.

Unfortunately this way is very slow.

This is the reason why i want to read every word, hoping this way is faster.

For reason that I dont know, Illustrator reads words in a strange way

Any ideas?

Translate
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 Expert ,
May 09, 2011 May 09, 2011
LATEST

Mark's script works as advertised, I got all 7 segments separated by tabs

getWordsSeparatedByTabs.gif

-

HK
Profondita sgambatura
da fianco a fondo abbottonato
(0197)
(0002)
(04)

Translate
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