Copy link to clipboard
Copied
Hello:
I get a number of photos that need to be mug shot size, and I'm new to scripting.
I have this but when I run it, nothing happens, so I know I've got something wrong.
But I'm at a loss of what to do to correct the issue. I've tried several different syntex, but I get error messages when I change things.
Any help would be appreicated.
Thanks, Larry
var mySelection = app.selection;
mySelection = mySelection.geometricBounds = ["0.7303 in", "1.0889 in"];
1 Correct answer
Hi Larry,
Try the following code, by selecting the rectangle that contains the image
var mySelection = app.selection[0];
var gm = mySelection.geometricBounds
//Save the value, and set it to inches
var origUnit = app.scriptPreferences.measurementUnit
app.scriptPreferences.measurementUnit = MeasurementUnits.INCHES
mySelection.geometricBounds = [gm[0], gm[1], gm[0] + 0.7303, gm[1] + 1.0889];
mySelection.fit(FitOptions.CONTENT_TO_FRAME)
//Restore the value
app.scriptPreferences.measurementUnit = o
...
Copy link to clipboard
Copied
Hi Larry,
Try the following code, by selecting the rectangle that contains the image
var mySelection = app.selection[0];
var gm = mySelection.geometricBounds
//Save the value, and set it to inches
var origUnit = app.scriptPreferences.measurementUnit
app.scriptPreferences.measurementUnit = MeasurementUnits.INCHES
mySelection.geometricBounds = [gm[0], gm[1], gm[0] + 0.7303, gm[1] + 1.0889];
mySelection.fit(FitOptions.CONTENT_TO_FRAME)
//Restore the value
app.scriptPreferences.measurementUnit = origUnit
In your code you tried to change the geometricBounds of app.selection, however app.selection is a collection of objects. So i used just one of the objects of the selection using app.selection[0], if you have multiple items in selection you can get reference to them using the index likeapp.selection[0], app.selection[1] etc
GemetricBounds is an array with values like [y1, x1, y2, x2] giving the coordinates of top, left and bottom, right points. So you need to keep the top, left the same and add values to the bottom right to resize the rectangle. Now once that is done we also need to fit the image inside the rectangle, here i used the Content to Frame option you can choose any of the available values
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#FitOptions.html
Also all this can be done using the resize method of rectangle as well, try it
-Manan
Copy link to clipboard
Copied
Wow! That worked.
Thanks so much, Manan.
I've been banging my head against the wall trying to figure this out.
Thanks again.
Larry
Copy link to clipboard
Copied
Also, the bounds are an array of numbers [y1, x1, y2, x2]. If for some reason you do not want to set and reset the measurement prefs, it is possible to coerce the numbers into a string and use "in" as you did in your first post:
var mySelection = app.selection[0];
var gm = mySelection.geometricBounds
//1.0889" width x .7303" height
mySelection.geometricBounds = [gm[0], gm[1], (gm[0] + 0.7303 ).toString() + " in", (gm[1] + 1.0889).toString() + " in"];
Copy link to clipboard
Copied
Thanks, Rob:
This is great...It worked. I've been trying, unsuccesfully, for several days to get my script to work, trying different configurations, and none worked.
I appreciate you helping me out.
Thanks again,
Larry

