Copy link to clipboard
Copied
Hi All.
I try to get all the words in a paragraph
MyTextFrame.paragraphs
If I read the contents of any word:
for (c = 0; c < MyTextFrame.paragraphs
{
currentWord = MyTextFrame.paragraphs
..
..
}
some words appears more then one time and other have less characters than the original
Someone can tell me why?
thanks
Ivan
Copy link to clipboard
Copied
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) }
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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…
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Mark's script works as advertised, I got all 7 segments separated by tabs
-
HK
Profondita sgambatura
da fianco a fondo abbottonato
(0197)
(0002)
(04)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now