EDOBE XDOM TPC Technical Information Page 47

  • Download
  • Add to my manuals
  • Print
  • Page
    / 68
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 46
CHAPTER 5: Scripting with JavaScript Accessing and referencing objects 47
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 objects
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()
Page view 46
1 2 ... 42 43 44 45 46 47 48 49 50 51 52 ... 67 68

Comments to this Manuals

No comments