C
5: Scripting with JavaScript
HAPTER
Working with selections
When the user makes a selection in a document, the selected objects are stored in the document's
selection
var selectedObjects = app.activeDocument.selection;
The
selection
objects are selected. To get or manipulate the properties of the selected art items, you must retrieve the
individual items in the array. To find out an object's type, use the
The following sample gets the first object in the array, then displays the object's type:
var topObject = app.activeDocument.selection[0];
alert(topObject.typename)
The first object in a selection array is the selected object that was last added to the page, not the last object
selected.
Selecting artwork objects
To select an art object, use the object's
Working with text frames
To create a text frame of a specific type in JavaScript, use the
corresponds to the text frame's type; for example:
var rectRef = docRef.pathItems.rectangle(700, 50, 100, 100);
//use the areaText method to create the text frame
var areaTextRef = docRef.textFrames.areaText(rectRef);
Threaded frames
As in the Illustrator application, you can thread area text frames or path text frames.
To thread existing text frames, use the
When copying the following script to the ESTK, place the value of the
var myDoc = documents.add();
var myPathItem1 = myDoc.pathItems.rectangle(244, 64, 82, 76);
var myTextFrame1 = myDoc.textFrames.areaText(myPathItem1);
var myPathItem2 = myDoc.pathItems.rectangle(144, 144, 42, 116);
var myTextFrame2 = myDoc.textFrames.areaText(myPathItem2);
// use the nextFrame property to thread the text frames
myTextFrame1.nextFrame = myTextFrame2;
var sText = "This is two text frames linked together as one story, with text
flowing from the first to the last. This is two text frames linked together as one
story, with text flowing from the first to the last. This is two text frames linked
together as one story. ";
myTextFrame1.contents = sText;
redraw();
property. To access all selected objects in the active document:
property value can be an array of any type of art objects, depending on what types of
property.
selected
textFrames
or
nextFrame
previousFrame
Working with text frames 44
property.
typename
method whose name
property of the
text frame
property on one line.
contents
object.