The value of a documents zeroPoint
property is an array of two numbers.
- The number at index 0 is the zero point on the X axis
- The number at index 1 is the zero point on the Y axis.
For example:
app.activeDocument.zeroPoint;
yields [0,0]
for a newly created document, i.e. for a document whose zero point has not been changed from its default position.
Example usage:
When creating a new page item it's necessary to calculate the zeroPoint
values to ensure you are positioning it at the desired location.
Example A:
Let's say we want to add a new square shaped text frame on the first page of a document that's always positioned at the top-left corner of the page regardless of the current zero point position.
In which case our code will be akin to the following:
var doc = app.activeDocument;
// 1. Obtain the zero point on the x axis.
var zeroPointX = doc.zeroPoint[0];
// 2. Obtain the zero point on the y axis.
var zeroPointY = doc.zeroPoint[1];
// 3. Create a new text frame that is always positioned at the top left corner
// of the first page, regardless of the zero point position.
doc.pages.item(0).textFrames.add({
geometricBounds: [
0 - zeroPointY,
0 - zeroPointX,
50 - zeroPointY,
50 - zeroPointX
],
contents: "Lorem ipsum dolore"
});
As you can see, in the preceding example, we subtract the zeroPointX
and zeroPointY
values from the desired geometricBounds
values accordingly when defining them for the new text frame.
Example B:
Calculating the the zeroPoint
values when setting the geometricBounds
can become tedious, particularly when creating multiple page items. It's often simpler and more efficient to:
- Obtain the current zero points
[x,y]
.
- Set the x and y zero points both to zero.
- Then create/add the new page item(s).
- Finally, revert the zero points to their original position.
The following gist demonstrates the aforementioned approach:
var doc = app.activeDocument;
// 1. Obtain the original zero point.
var originalZeroPoints = doc.zeroPoint;
// 2. Set x and y zero points both to zero.
doc.zeroPoint = [0,0];
// 3. Create a new text frame that is always positioned at the top left corner
// of the first page, regardless of the zero point position.
doc.pages.item(0).textFrames.add({
geometricBounds: [0, 0, 50, 50],
contents: "Lorem ipsum dolore"
});
// 4. Revert the zero point to original position.
doc.zeroPoint = originalZeroPoints;
As you can see, in this preceding example it produces the same result as "Example A", however we don't do any calculations when setting the geometricBounds
, instead we simply define our values as desired, i.e. geometricBounds: [0, 0, 50, 50]