Answered
Remove the images
Hi,
The image frame used to be removed from the InDesign document after the images had been placed in the newly added frames on another page. Below you will find the script I used to remove the image. However, I have been unable to remove existing images from the Indesign document using the script.
var doc = app.activeDocument;
var page = doc.pages[i];
var pageHeight = page.bounds[2] - page.bounds[0];
// Loop through all text frames on the page
for (var j = 0; j < page.textFrames.length; j++) {
var frame = page.textFrames[j];
var pageValue = app.activeWindow.activePage + 1;
var imageNamesArray = [];
imageNamesArray.splice(0, imageNamesArray.length);
// Loop through each item on the active page
for (var m = 0; m < page.allPageItems.length; m++) {
// Get a reference to the current page item
var item = page.allPageItems[m];
// Check if the current item is an image and log its name
if (item instanceof Image) {
var imageName = item.itemLink.name;
if (imageName.length > 0) {
imageNamesArray.push(imageName);
}
}
}
}
var frameWidth = 100;
var frameHeight = 50;
var frameX = 60;
var frameY = 640;
for (var k = 0; k < imageNamesArray.length; k++) {
// Get the path to the image file
var imagePath = FolderPath() + "/" + imageNamesArray[k];
var activePage = app.activeWindow.activePage;
var activePageNum = activePage.documentOffset;
var currentFrameX = frameX + k * (frameWidth + 10);
var newFrame = activePage.textFrames.add({
geometricBounds: [frameY, currentFrameX, frameY + frameHeight, currentFrameX + frameWidth]
});
// Place the image in the new text frame
var placedItem = newFrame.place(File(imagePath));
newFrame.fit(FitOptions.proportionally);
// Remove the original image frame
var item = placedItem.parent;
if (item instanceof Image) {
var parentFrame = item.parent;
parentFrame.remove();
}
}
