amanm5143 wrote 2. I had set the Auto-sizing Option in the Text Frame Options to "Width and Height" [...] Though the script worked but it cropped the right side part of the image to fit to the width and bottom part to fit to the height. Basically, it trimmed the images to fit to the size of text frame. |
Well, I actually meant Object style > Fitting options, not Text Frame Options > Auto-sizing.
This is why your images got cropped.
Now, thinking about it, maybe auto-fitting is not what you want...
So, lets think differently. Instead of resizing the frame, let's rescale it.
Give this version 2 script a try and tell me if it works for you.
Besides, I modified it because not everyone works in millimeters... It now should work whatever measurement units are in use.
I also "wrapped" it, so you can CTRL-Z it now...
//FitAnchorToColumn v2
//Transform anchored objects in order to rescale them to make them fit column width, keeping proportions.
//by Vinny
if (parseFloat(app.version) < 6)
main();
else
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "FitAnchorToColumn");
function main() {
if (app.documents.length > 0) {
var
myDoc = app.activeDocument,
docUnits = myDoc.viewPreferences.horizontalMeasurementUnits;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "~a"
var myFound = myDoc.findGrep();
for (i = 0; i < myFound.length; i++) {
if (typeof myFound.parentTextFrames[0] != "undefined") {
var columnWidth = myFound.parentTextFrames[0].textFramePreferences.textColumnFixedWidth,
myObjectWidth = myFound.pageItems[0].geometricBounds[3]-myFound.pageItems[0].geometricBounds[1],
myScaleFactor = columnWidth/myObjectWidth,
myScaleMatrix = app.transformationMatrices.add({horizontalScaleFactor:myScaleFactor,verticalScaleFactor:myScaleFactor});
myFound.pageItems[0].transform(
CoordinateSpaces.INNER_COORDINATES,
AnchorPoint.TOP_LEFT_ANCHOR,
myScaleMatrix
);
}
}
app.findGrepPreferences = app.changeGrepPreferences = null;
} else {
alert("Open a document");
}
}
amanm5143 wrote Additionally, it didn't run on every text frame; I had to select each text frame and run the script again to make the desired changes. |
Hmmmm... that's strange. I don't know what to tell you. It should affect the whole document...
Let's see if version 2 magically solves it ^^