CharacterStyles
CharacterStyles
Section titled “CharacterStyles”app.activeDocument.characterStyles
Description
Section titled “Description”A collection of CharacterStyle objects.
Properties
Section titled “Properties”CharacterStyles.length
Section titled “CharacterStyles.length”app.activeDocument.characterStyles.length
Description
Section titled “Description”The number of characters in the collection.
Number; read-only.
CharacterStyles.parent
Section titled “CharacterStyles.parent”app.activeDocument.characterStyles.parent
Description
Section titled “Description”The object’s container.
Object; read-only.
CharacterStyles.typename
Section titled “CharacterStyles.typename”app.activeDocument.characterStyles.typename
Description
Section titled “Description”The class name of the object.
String; read-only.
Methods
Section titled “Methods”CharacterStyles.add()
Section titled “CharacterStyles.add()”add(name)
Description
Section titled “Description”Creates a named character style.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
name | String | Element name to create |
Returns
Section titled “Returns”CharacterStyles.getByName()
Section titled “CharacterStyles.getByName()”getByName(name)
Description
Section titled “Description”Gets the first element in the collection with the provided name.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
name | String | Name of element to get |
Returns
Section titled “Returns”CharacterStyles.index()
Section titled “CharacterStyles.index()”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”CharacterStyles.removeAll()
Section titled “CharacterStyles.removeAll()”removeAll()
Description
Section titled “Description”Deletes all elements in this collection.
Returns
Section titled “Returns”Nothing.
Example
Section titled “Example”Using characters styles
Section titled “Using characters styles”// Creates 3 text frames in a new document then creates// a character style and applies it to each text frame.
var docRef = documents.add();var textRef1 = docRef.textFrames.add();textRef1.contents = "Scripting is fun!";textRef1.top = 700;textRef1.left = 50;
var textRef2 = docRef.textFrames.add();textRef2.contents = "Scripting is easy!";textRef2.top = 625;textRef2.left = 100;
var textRef3 = docRef.textFrames.add();textRef3.contents = "Everyone should script!";textRef3.top = 550;textRef3.left = 150;redraw();
// Create a new character stylevar charStyle = docRef.characterStyles.add("BigRed");
// set character attributesvar charAttr = charStyle.characterAttributes;charAttr.size = 40;charAttr.tracking = -50;charAttr.capitalization = FontCapsOption.ALLCAPS;
var redColor = new RGBColor();redColor.red = 255;redColor.green = 0;redColor.blue = 0;charAttr.fillColor = redColor;
// apply to each textFrame in the documentcharStyle.applyTo(textRef1.textRange);charStyle.applyTo(textRef2.textRange);charStyle.applyTo(textRef3.textRange);