Words
app.activeDocument.textFrames[index].words
Description
Section titled “Description”A collection of words in a text item, where each word is a TextRange object.
The elements are not named; you must access them by index.
Properties
Section titled “Properties”Words.length
Section titled “Words.length”app.activeDocument.textFrames[index].words.length
Description
Section titled “Description”The number of objects in the collection
Number; read-only.
Words.parent
Section titled “Words.parent”app.activeDocument.textFrames[index].words.parent
Description
Section titled “Description”The parent of this object.
Object; read-only.
Words.typename
Section titled “Words.typename”app.activeDocument.textFrames[index].words.typename
Description
Section titled “Description”The class name of the referenced object.
String; read-only.
Methods
Section titled “Methods”Words.add()
Section titled “Words.add()”app.activeDocument.textFrames[index].words.add(contents[, relativeObject][, inseertLocation])
Description
Section titled “Description”Adds a word to the current document at the specified location.
If no location is specified, adds it to the containing text frame after the current word selection or insertion point.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
contents | String | Word to add |
relativeObject | TextFrameItem, optional | Object to add item to |
insertionLocation | ElementPlacement, optional | Location to insert text |
Returns
Section titled “Returns”Words.addBefore()
Section titled “Words.addBefore()”app.activeDocument.textFrames[index].words.addBefore(contents)
Description
Section titled “Description”Adds a word before the current word selection or insertion point.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
contents | String | Word to add |
Returns
Section titled “Returns”Words.index()
Section titled “Words.index()”app.activeDocument.textFrames[index].words.index(itemKey)
Description
Section titled “Description”Gets an element from the collection.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
itemKey | String, Number | String or number key |
Returns
Section titled “Returns”Words.removeAll()
Section titled “Words.removeAll()”app.activeDocument.textFrames[index].words.removeAll()
Description
Section titled “Description”Deletes all elements in this collection.
Returns
Section titled “Returns”Nothing.
Example
Section titled “Example”Counting words
Section titled “Counting words”// Counts all words in current document and stores total in numWordsif ( app.documents.length > 0 ) { var numWords = 0;
for ( i = 0; i < app.activeDocument.textFrames.length; i++) { numWords += app.activeDocument.textFrames[i].words.length; }}
Applying attributes to words
Section titled “Applying attributes to words”// Creates a new magenta color and applies the color to all words meeting a specific criteriaif (app.documents.length > 0 && app.activeDocument.textFrames.length > 0) { // Create the color to apply to the words var wordColor = new RGBColor(); wordColor.red = 255; wordColor.green = 0; wordColor.blue = 255;
// Set the value of the word to look for searchWord1 = "the"; var searchWord2 = "The"; var searchWord3 = "THE";
// Iterate through all words in the document // and color the words that match searchWord
for (var i = 0; i < app.activeDocument.textFrames.length; i++) { var textArt = activeDocument.textFrames[i];
for (var j = 0; j < textArt.words.length; j++) { var word = textArt.words[j];
if (word.contents == searchWord1 || word.contents == searchWord2 || word.contents == searchWord3) { word.filled = true; word.fillColor = wordColor; } } }}