• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Move Images to the Bottom of the Page

Explorer ,
Apr 20, 2023 Apr 20, 2023

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]);
}
}

 

TOPICS
How to , Scripting

Views

221

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 30, 2023 Apr 30, 2023

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

  • Do we need the splice method call?
  • imagePath variable is not used

-Manan

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 30, 2023 Apr 30, 2023

Copy link to clipboard

Copied

LATEST

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:

Screen Shot 18.png

 

After:

Screen Shot 19.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines