Adobe 65010248 Scripting Guide - Page 43
Creating new objects, in the document, use its
UPC - 883919156484
View all Adobe 65010248 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 43 highlights
CHAPTER 5: Scripting with JavaScript Accessing and referencing objects 43 The following statements assign the name of the first graphic style in the collection to a variable. You can use these statements interchangeably. var styleName = myStyles[0].name var styleName = firstStyle.name var styleName = app.activeDocument.graphicStyles[0].name To get the total number of objects in a collection, use the length property: alert ( myStyles.length ); The index of the last graphic style in the collection is myStyles.length-1 (-1 because the collection starts the index count at 0 and the length property counts from 1): var lastStyle = myStyles[ myStyles.length - 1 ]; Note that an expression representing the index value is enclosed in square brackets ([]) as well as quotes. If you know the name of an object, you can access the object in the collections using the name surrounded by square brackets; for example: var getStyle = myStyles[Ice Type]; Each element in the collection is an object of the desired type, and you can access its properties through the collection. For example, to get an object's name, use the name property: var styleName = app.activeDocument.graphicStyles[0].name; To apply lastStyle to the first pageItem in the document, use its applyTo() method: lastStyle.applyTo( app.activeDocument.pageItems[0] ); Creating new objects You can use a script to create new objects. To create objects that are available from collection objects, or containers, use the container object's add() method: var myDoc = app.documents.add() var myLayer = myDoc.layers.add() Some object types are not available from containers. To create an object of this type, define a variable, then use the new operator with an object constructor to assign an object as the value. For example, to create a new CMYKColor object using the variable name myColor: var myColor = new CMYKColor()