Characters
Characters
Section titled “Characters”app.activeDocument.textFrames[index].contents
Description
Section titled “Description”A collection of characters (TextRange
objects of length 1).
The elements are not named; you must access them by index.
Properties
Section titled “Properties”Characters.length
Section titled “Characters.length”app.activeDocument.textFrames[index].contents.length
Description
Section titled “Description”The number of characters in the collection.
Number; read-only.
Characters.parent
Section titled “Characters.parent”app.activeDocument.textFrames[index].contents.parent
Description
Section titled “Description”The text art item that contains this character.
Object; read-only.
Characters.typename
Section titled “Characters.typename”app.activeDocument.textFrames[index].contents.typename
Description
Section titled “Description”The class name of the referenced object.
String; read-only.
Methods
Section titled “Methods”Characters.add()
Section titled “Characters.add()”app.activeDocument.textFrames[index].contents.add(contents[,relativeObject][,insertionLocation])
Description
Section titled “Description”Adds a new character with specified text contents at the specified location in the current document.
If a location is not specified, adds the new character to the containing text frame after the current text selection or insertion point.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
contents | String | Text contents to add |
relativeObject | TextFrameItem, optional | Object to add item to |
insertionLocation | ElementPlacement, optional | Location to place text |
Returns
Section titled “Returns”Characters.addBefore()
Section titled “Characters.addBefore()”app.activeDocument.textFrames[index].contents.addBefore(contents)
Description
Section titled “Description”Adds a character before the specified text selection.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
contents | String | Text contents to add |
Returns
Section titled “Returns”Characters.index()
Section titled “Characters.index()”app.activeDocument.textFrames[index].contents.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”Characters.removeAll()
Section titled “Characters.removeAll()”app.activeDocument.textFrames[index].contents.removeAll()
Description
Section titled “Description”Deletes all elements in the collection.
Returns
Section titled “Returns”Nothing.
Example
Section titled “Example”Counting characters
Section titled “Counting characters”// Counts all characters in the active document,// including whitespace, and stores in numChars
if (app.documents.length > 0) { var doc = app.activeDocument; var numChars = 0; for (var i = 0; i < doc.textFrames.length; i++) { var textArtRange = doc.textFrames[i].contents; numChars += textArtRange.length; }}