Copy link to clipboard
Copied
How run the above script only in page specified in myArr
var myDoc = app.activeDocument;
var tfs = myDoc.allGraphics;
var myFrames = myDoc.textFrames;
var myArr = [15,16,20,22]
var A = -5
var B = 0
var C = 120
var D = 175
for (var i = 0; i < tfs.length; i++) {
try {
var myPage = tfs[i].parentPage;
tfs[i].parent.geometricBounds = [A, B, C, D];
tfs[i].geometricBounds = [A, B, C, D];
}
} catch(e){}
}
You can get the itemLayer of the graphic and check its name or locked status. Change "LayerName" to the name of your layer
function setBounds(p,b){
var tfs = p.allGraphics;
for (var i = 0; i < tfs.length; i++) {
if (tfs[i].itemLayer.name == "LayerName") {
tfs[i].parent.geometricBounds = b;
tfs[i].geometricBounds = b;
}
}
}
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Graphic.html
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Layer.html#d1e200146
...Looks like a rounding difference on the conversion from the PDF’s size in inches to millimeters. If I inspect the PDF Acrobat reports the trim dimension as 6.693" x 4.724"
Those inch dimensions don’t convert to exactly 170mm x 120mm:
The script could force the scale of the graphic to 100%:
var myDoc = app.activeDocument;
//an array of page names
var pa = [1,16,20,22]
//the bounds to use
var ba = [-5,0,115,170]
//set units for bounds—points?
app.scriptPreferences.measurementUnit = M
...
Copy link to clipboard
Copied
Hi @lux65 , Maybe wrap your bounds setting in a function, then loop thru your page array to set the graphic bounds—something like this?
var myDoc = app.activeDocument;
//an array of page names
var pa = [15,16,20,22]
//the bounds to use
var ba = [-5,0,120,175]
//set units for bounds—points?
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
//the target page
var p;
for (var i = 0; i < pa.length; i++){
//get the target page by name
p = myDoc.pages.itemByName(pa[i].toString())
//if the page exists run the function
if (p.isValid) {
setBounds(p,ba)
}
};
app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;
/**
* Sets the bounds of all the graphics on the specified page
* @ param target page object
* @ param the bounds to set
* @ return void
*/
function setBounds(p,b){
var tfs = p.allGraphics;
for (var i = 0; i < tfs.length; i++) {
tfs[i].parent.geometricBounds = b;
tfs[i].geometricBounds = b;
}
}
Copy link to clipboard
Copied
Thank you rob day.
It's quite perfect.
It's possible make it works only on visible or unlocked layers? or specific named layer?
Copy link to clipboard
Copied
You can get the itemLayer of the graphic and check its name or locked status. Change "LayerName" to the name of your layer
function setBounds(p,b){
var tfs = p.allGraphics;
for (var i = 0; i < tfs.length; i++) {
if (tfs[i].itemLayer.name == "LayerName") {
tfs[i].parent.geometricBounds = b;
tfs[i].geometricBounds = b;
}
}
}
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Graphic.html
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Layer.html#d1e200146
Copy link to clipboard
Copied
Perfect!
Thank you!
Copy link to clipboard
Copied
Due to a Indesign approximate conversion from points to mm, despite bounds of graphic and container are the same measures, the percentage shown in Indesign it's never 100% but always with many decimals (99,99999 or 100,00001). There isn't a workaroung to get more accurate conversion?
Copy link to clipboard
Copied
When you are setting bounds you have to set what units should be used. You can either set the document’s ruler unit preference, or the units used by the script, which is what I did in my example. If you want to use millimeters then set the scripting units to millimeters. Change:
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
to:
app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;
Copy link to clipboard
Copied
yes, I also try setting
MeasurementUnits.MILLIMETER
Width and height of graphic and container shown in Indesign are perfect, but not the percentage.
Copy link to clipboard
Copied
That’s because if the graphic is an image it would have a pixel dimension, and the pixels may or may not fit exactly to your 170mm x 120mm bounds—the image’s pixel grid can’t contain a partial pixel.
It’s easier to see the problem via Photoshop’s Image Size dialog. In this example the image pixel dimension is 2008px x 1417px. At 300ppi the 100% output dimensions are close to 170mm x 120mm, but not exact:
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Looks like a rounding difference on the conversion from the PDF’s size in inches to millimeters. If I inspect the PDF Acrobat reports the trim dimension as 6.693" x 4.724"
Those inch dimensions don’t convert to exactly 170mm x 120mm:
The script could force the scale of the graphic to 100%:
var myDoc = app.activeDocument;
//an array of page names
var pa = [1,16,20,22]
//the bounds to use
var ba = [-5,0,115,170]
//set units for bounds—points?
app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;
//the target page
var p;
for (var i = 0; i < pa.length; i++){
//get the target page by name
p = myDoc.pages.itemByName(pa[i].toString())
//if the page exists run the function
if (p.isValid) {
setBounds(p,ba)
}
};
app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;
/**
* Sets the bounds of all the graphics on the specified page
* @ param target page object
* @ param the bounds to set
* @ return void
*/
function setBounds(p,b){
var tfs = p.allGraphics;
for (var i = 0; i < tfs.length; i++) {
tfs[i].parent.geometricBounds = b;
tfs[i].geometricBounds = b;
tfs[i].horizontalScale = 100;
tfs[i].verticalScale = 100;
}
}
Copy link to clipboard
Copied
Thank you rob day!