Hi Uwe,
I totally agree with you: this approach is far from perfect. However, the OP, if I got him right, wanted simply 'record' the three steps and 'replay' them against all the images in a document (or maybe even in all open documents, or in all documents in a folder). Probably the images in his documents are not scaled and not rotated, etc. so what you described in your post 8 isn't applicable to his particular situation. This is, as I've already mentioned, a quick-and-dirty script and I didn't promise it would work for everyone in all circumstances.
Anyway, here's a new -- a little improved version -- added a try-catch block in case something goes wrong: e.g. the "Freisteller" alpha channel is missing.
Forgot to mention: the user can Undo-Redo the whole script.
var scriptName = "FitFrame2Content",
doc;
app.doScript(PreCheck, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "\"" + scriptName + "\" Script");
//===================================== FUNCTIONS ======================================
function Main() {
var link, image, container, clippingPath,
links = doc.links;
for (var i = 0; i < links.length; i++) {
try {
link = links;
if (link.linkType == "TIFF" || link.linkType == "Photoshop") {
image = link.parent;
container = image.parent;
clippingPath = image.clippingPath;
with (clippingPath) {
clippingType = ClippingPathType.ALPHA_CHANNEL;
appliedPathName = "Freisteller";
insetFrame = -2;
threshold = 25;
tolerance = 2;
includeInsideEdges = false;
invertPath = false;
restrictToFrame= false;
useHighResolutionImage = true;
}
container.fit(FitOptions.FRAME_TO_CONTENT);
clippingPath.clippingType = ClippingPathType.NONE;
}
}
catch(err) {
$.writeln(err.message + ", line: " + err.line);
}
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function PreCheck() {
if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true);
doc = app.activeDocument;
if (doc.converted) ErrorExit("The current document has been modified by being converted from older version of InDesign. Please save the document and try again.", true);
if (!doc.saved) ErrorExit("The current document has not been saved since it was created. Please save the document and try again.", true);
Main();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function ErrorExit(error, icon) {
alert(error, scriptName, icon);
exit();
}
Regards,
Kasyan