Copy link to clipboard
Copied
Hey,
need to do this:
I have multiple pages on single InDesign document, each page has one single text frame which contains a table with different heights. I'd need to resize the pages based on the size of the text frame. Since there is more than 100 pages, doing it by hand with Page Tool is a bit of frustrating task.
Any idea how to make a script/action out of it?
Copy link to clipboard
Copied
Hi,
this is the first time I try to resize something. Try the following lines:
var curDoc = app.activeDocument;
var allPages = curDoc.pages;
hM = curDoc.viewPreferences.horizontalMeasurementUnits;
vM = curDoc.viewPreferences.verticalMeasurementUnits;
curDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
curDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
for ( var i = 0; i < allPages.length; i++ ) {
var curPage = allPages;
var tf = curPage.textFrames[0];
var tfWidth = tf.geometricBounds[3] - tf.geometricBounds[1];
var tfHeight = tf.geometricBounds[2] - tf.geometricBounds[0];
curPage.resize(CoordinateSpaces.INNER_COORDINATES,
AnchorPoint.TOP_LEFT_ANCHOR,
ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
[tfWidth, tfHeight]);
tf.move([0,0]);
}
curDoc.viewPreferences.horizontalMeasurementUnits = hM;
curDoc.viewPreferences.verticalMeasurementUnits = vM;
Some questions to the advanced scripters:
1. What does 'CoordinateSpaces.INNER_COORDINATES' means?
2. How can I check the values of 'CoordinateSpaces'?
3. Why do I get an error, if the rulers are set to 'mm' instead of points? I assume that it has something to do with margins? But I’m not able to find the real problem.
Thanks
Kai
Copy link to clipboard
Copied
Kai,
> What does 'CoordinateSpaces.INNER_COORDINATES' mean?
See http://www.indiscripts.com/post/2014/03/coordinate-spaces-and-transformations-1
> 2. How can I check the values of 'CoordinateSpaces'?
> 3. Why do I get an error, if the rulers are set to 'mm' instead of points?
resize() defaults to points and doesn't accept strings like "100 mm". If you want to set values as e.g. mm, you need UnitValue to convert those values to points, as in:
. . .
. . .
ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
[UnitValue('100','mm').as('pt'), UnitValue('150','mm').as('pt')]);
Peter
Copy link to clipboard
Copied
Hi my friend,
thanks for your explanation and the link for Marcs PDF .
best
Kai
Copy link to clipboard
Copied
Gee, I need to study scripting from basic... honestly don't understand a word...
But thanks for responce. Will look into this, need to get more productive!
Copy link to clipboard
Copied
If you run the script, it should do what you want.
Copy link to clipboard
Copied
Yep, it did. Magical.
Thanks guys!
Copy link to clipboard
Copied
Hi guys,
In ID CS5.5 and later you also can take advantage of the Page.reframe() method, leading to a more robust implementation—IMHO.
Indeed, suppose the layout contains transformed frames in various weird contexts (rotated views, unusual measurement units, ruler-per-page mode and so on) then script based on PageItem.geometricBounds calculations will generally fail.
From the initial state shown below,
the user probably expects the following result:
A good approach is to consider both Page and TextFrame objects as simple 'spread items' and to use the SPREAD COORDINATE SPACE as a reliable reference. Dimensions and bounding boxes are then seen from the spread perspective, and the code remains very compact:
// =========================================================
// SHOULD WORK IN ID CS5.5 AND LATER
// Fit pages to 1st textframe
// =========================================================
const CS_SPREAD = +CoordinateSpaces.spreadCoordinates,
BB_VISIBLE = +BoundingBoxLimits.outerStrokeBounds,
TOP_LEFT = [[0,0],BB_VISIBLE,CS_SPREAD],
BOT_RIGHT = [[1,1],BB_VISIBLE,CS_SPREAD],
// ---
getXY = function(o,c){ return o.resolve(c, CS_SPREAD)[0] },
// ---
fitToFirstFrame = function(/*Pages*/o, i,t)
{
for(
i=o.count() ; i-- ; (t=o.textFrames[0]).isValid &&
o.reframe(CS_SPREAD,[getXY(t, TOP_LEFT),getXY(t, BOT_RIGHT)])
);
};
// ---
// SAMPLE CODE
// ---
var curDoc = app.properties.activeDocument;
curDoc && fitToFirstFrame(curDoc.pages);
As you can see there is no need to manage custom measurement units or to manually address weird cases.
Hope that helps.
@+
Marc
Copy link to clipboard
Copied
Hi Marc,
thanks for your code. It works. But to be honest , as a (advanced) beginner I do not understand what is going on here and your compact code is hard to understand for me.
I fail already to understand what is the contents of the variables (especially what the '+'Symbol does) and what is going on in the function. Also not clear, what is going on in getXY and why do you use 'app.properties.activeDocument' ??
Copy link to clipboard
Copied
Hi Kai,
Sorry for my obscure code. In fact, all about coordinate spaces and transform methods is obscure in Adobe's documentation. Syntax and parameters that I use often reflect under-documented features that need to be clarified, indeed! I started a paper on this subject at Indiscripts :: Coordinate Spaces and Transformations in InDesign — Chap.1 but there is still a lot to write up.
NB: The '+' symbol has virtually no importance in my code. You could remove it as well. I just got used to store lightweight data in constants to avoid unnecessary object references.
+CoordinateSpaces.spreadCoordinates is just the number (uint) behind CoordinateSpaces.spreadCoordinates (which is an Enumerator).
@+
Marc
Copy link to clipboard
Copied
Hi Marc,
thanks for clarification. As a graphic designer I like (or it is more helpful to me) a more detailed explanation - maybe with comments - instead of this short ones . The way you did this in some posts these days is much appreciated .