CHAPTER 5: Working with Page Items Transforming Page Items 66
var myRectangle =
app.documents.item(0).pages.item(0).groups.item(-1).rectangles.item(0);
alert("The page contains a group which has been\rrotated 45 degrees
(counterclockwise).\rThe rectangle inside the group was\rrotated 45 degrees
counterclockwise\rbefore it was added to the group.\r\rWatch as we apply a series of
scaling\roperations in different coordinate spaces.");
var myTransformationMatrix =
app.transformationMatrices.add({horizontalScaleFactor:2});
//Transform the rectangle using inner coordinates.
myRectangle.transform(CoordinateSpaces.innerCoordinates, AnchorPoint.centerAnchor,
myTransformationMatrix);
//Select the rectangle and display an alert.
app.select(myRectangle);
alert("Transformed by inner coordinates.");
//Undo the transformation.
app.documents.item(0).undo();
//Transform using parent coordinates.
myRectangle.transform(CoordinateSpaces.parentCoordinates, AnchorPoint.centerAnchor,
myTransformationMatrix);
app.select(myRectangle);
alert("Transformed by parent coordinates.");
app.documents.item(0).undo();
//Transform using pasteboard coordinates.
myRectangle.transform(CoordinateSpaces.pasteboardCoordinates,
AnchorPoint.centerAnchor, myTransformationMatrix);
app.select(myRectangle);
alert("Transformed by pasteboard coordinates.");
app.documents.item(0).undo();
Transformation origin
The transformation origin is the center point of the transformation. The transformation origin can be
specified in several ways:
X Bounds space:
Z anchor — An anchor point on the object itself.
AnchorPoint.centerAnchor
Z
anchor, bounds type — An anchor point specified relative to the geometric bounds of the object
(
BoundingBoxLimits.geometricPathBounds) or the visible bounds of the object
(
BoundingBoxLimits.outerStrokeBounds).
[AnchorPoint.bottomLeftAnchor, BoundingBoxLimits.outerStrokeBounds]
Z
anchor, bounds type, coordinate system — An anchor point specified as the geometric bounds of
the object (
BoundingBoxLimits.geometricPathBounds) or the visible bounds of the object
(
BoundingBoxLimits.outerStrokeBounds) in a given coordinate space.
[AnchorPoint.bottomLeftAnchor, BoundingBoxLimits.outerStrokeBounds,
CoordinateSpaces.pasteboardCoordinates]
Z
(x,y), bounds type — A point specified relative to the geometric bounds of the object
(
BoundingBoxLimits.geometricPathBounds) or the visible bounds of the object
(
BoundingBoxLimits.outerStrokeBounds). In this case, the top-left corner of the bounding box
is (0, 0); the bottom-right corner, (1, 1). The center anchor is located at (.5, .5).
[[.5, .5], BoundingBoxLimits.outerStrokeBounds]