Copy link to clipboard
Copied
This script is used to import the picture, the format contains the article contains: @ name.jpg (or tif / psd) @
I want to add some functionality:
The image is automatically applied to the specified object style.
Also, the picture automatically equals to 1/3 of the page size
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Below is the original script,Thanks to Kasyan
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
main();
function main() {
var name, f, file, text,
arr = [];
if(app.documents.length != 0) {
var doc = app.activeDocument;
var folder = Folder.selectDialog("Choose a folder with images");
if (folder != null) {
app.findObjectPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.findWhat = "@.+?@";
f = doc.findGrep(true);
for (i = 0; i < f.length; i++) {
name = f.contents.replace(/@/g, "");
file = new File(folder.fsName + "/" + name);
if (file.exists) {
f.remove();
f.insertionPoints[0].place(file);
}
else {
arr.push("File doesn't exist '" + name + "'");
}
}
app.findObjectPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
arr.push("------------------------------------------");
text = arr.join("\r");
writeToFile(text);
}
}
else{
alert("Please open a document and try again.");
}
}
function writeToFile(text) {
var file = new File("~/Desktop/Place inline images.txt");
if (file.exists) {
file.open("e");
file.seek(0, 2);
}
else {
file.open("w");
}
file.write(text + "\r");
file.close();
}
Copy link to clipboard
Copied
Hi,
then I would:
1. Place the graphic to a prepared graphic frame. Not at the insertion point.
So you couuld best workaround of a possible text and graphic overflow, if the image is too large for the text frame.
// Pseudo code where myObjectStyle and myGeometricBounds should be defined first:
var newFrame = app.documents[0].rectangles.add({appliedObjectStyle : myObjectStyle , myGeometricBounds });
newFrame.place(file);
2. Anchor the graphic to the insertion point.
See method insertAnchoredObject() of the anchoredObjectSettings for the Rectangle class:
Adobe InDesign CS6 (8.0) Object Model JS: AnchoredObjectSetting
// Pseudo code continued:
newFrame.anchoredObjectSettings.insertAnchoredObject( f.insertionPoints[0] , AnchorPosition.INLINE_POSITION );
I don't know what you exactly mean by a third of your page.
Should the image exceed the width or the height of the text frame? I don't think so…
Regards,
Uwe