Copy link to clipboard
Copied
Hi,
I need to remove the images which is present in the top of each pages after placing the images to the bottom of the page which is shown in the "Output Document.indd". But while executing this script I'm able to place the frame in the bottom of the page at the sametime I cannot able to remove the images at the top of the page. The script I have used is given below. Please guide me on this..
var doc = app.activeDocument;
var frameX = 60;
var frameY =640;
var frameWidth = 50;
var frameHeight = 50;
for (var i = 0; i < doc.pages.length; i++) {
var page = doc.pages[i];
var imageNamesArray = [];
imageNamesArray.splice(0, imageNamesArray.length);
for (var m = 0; m < page.allPageItems.length; m++) {
var item = page.allPageItems[m];
if (item instanceof Image) {
var imageName = item.itemLink.name;
if (imageName.length > 0) {
imageNamesArray.push(imageName);
}
}
}
for (var q = 0; q < imageNamesArray.length; q++) {
var imagePath = FolderPath() + "/" + imageNamesArray[q];
var currentFrameX = frameX + q * (frameWidth + 10);
imageNamesArray[q].move(undefined, [frameY, currentFrameX, frameY + frameHeight, currentFrameX + frameWidth]);
}
}
Copy link to clipboard
Copied
I see number of issues in your code. The first thing that would result in a crash is that you are using the move method on
imageNamesArray[q]
However, if we look a little up in the code you push the image name in this array. So you are calling move method on a String, this will cause an error as String class does not have a move method.
Some other points that may not be errors but are worth having a look
-Manan
Copy link to clipboard
Copied
Hi @Barathi , You could simply move the items then distribute them. Something like this:
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;//using points as units
var api = app.activeWindow.activePage.allPageItems;//page items on active page
var spaceX = 10;//space between frames
var frameY = 660;//frameās Y
var b;
var ia = []
for (var i = 0; i < api.length; i++){
if (api[i].constructor.name == "Image") {
b = api[i].parent.geometricBounds
api[i].parent.move([b[1],frameY]);
ia.push(api[i].parent)
}
};
app.activeDocument.distribute(ia, DistributeOptions.HORIZONTAL_SPACE, AlignDistributeBounds.ITEM_BOUNDS, true, spaceX);
app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;//reset
Before:
After: