Grouping Page Items; Duplicating And Moving Page Items - Adobe 0046100128056 - InDesign - Mac Manual

Javascript
Table of Contents

Advertisement

C
5: Working with Page Items
HAPTER
//Given a polygon "myPolygon", remove the
//last path point in the first path.
myPolygon.paths.item(0).pathPoints.item(-1).remove();

Grouping Page Items

In the InDesign user interface, you create groups of page items by selecting them and then choosing
Group from the Object menu (or by pressing the corresponding keyboard shortcut). In InDesign scripting,
you tell the object containing the page items you want to group (usually a page or spread) to group the
page items, as shown in the Group script.
//Given a page "myPage" containing at least two ovals and two rectangles...
var myArray = new Array;
//Add the items to the array.
myArray.push(myPage.rectangles.item(0));
myArray.push(myPage.ovals.item(0));
myArray.push(myPage.rectangles.item(1));
myArray.push(myPage.ovals.item(1));
//Group the items.
myPage.groups.add(myArray);
To ungroup, you tell the group itself to ungroup, as shown in the Ungroup script.
//Given a group "myGroup"...
myPageItems = myGroup.ungroup();
There is no need to ungroup a group to change the shape, formatting, or content of the page items in the
group. Instead, simply get a reference to the page item you want to change, just as you would with any
other page item.

Duplicating and Moving Page Items

In the InDesign user interface, you can move page items by selecting them and dragging them to a new
location. You can also create copies of page items by copying and pasting, by holding down Option/Alt as
you drag an object, or by choosing Duplicate, Paste In Place, or Step and Repeat from the Edit menu. In
InDesign scripting, you can use the move method to change the location of page items, and the duplicate
method to create a copy of a page item (and, optionally, move it to another location).
The move method can take one of two optional parameters: moveTo and moveBy. Both parameters
consist of an array of two measurement units, consisting of a horizontal value and a vertical value. moveTo
specifies an absolute move to the location specified by the array, relative to the current location of the zero
point. moveBy specifies how far to move the page item relative to the current location of the page item
itself. The Move script shows the difference between these two approaches.
//Given a reference to a rectangle "myRectangle"...
//Move the rectangle to the location (12, 12).
//Absolute move:
myRectangle.move([12, 12]);
//Move the rectangle *by* 12 points horizontally, 12 points vertically.
//Relative move (note undefined first parameter):
myRectangle.move(undefined, [12, 12]);
//Move the rectangle to another page (rectangle appears at (0,0);
var myPage = app.documents.item(0).pages.add();
myRectangle.move(myPage);
//To move a page item to another document, use the duplicate method.
Grouping Page Items 59

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs5

Table of Contents