Skip to main content
Inspiring
August 23, 2024
Answered

replace ( relink ) images in certain pages with one image at the same time

  • August 23, 2024
  • 4 replies
  • 1309 views

Hi 

I have an indesign file of 400 pages , each page contain one image , Is there a script with simple interface to replace ( relink ) images in certain pages with one other image 

Ex : I want to select pages ( or enter page numbers )  4 , 16 , 50 , 60  at the same time , replace images in them with one image .

I mean that the other image is to duplicate , put instead of images in the selected pages

Thanks

Correct answer r36058804bwut

I reached to this code by chat GPT , works as a charm

----------------------------------------------------------------------------------

var doc = app.activeDocument;

// Create the main dialog
var dialog = app.dialogs.add({name: "Replace Images on Selected Pages"});

var result = dialog.dialogColumns.add().staticTexts.add({
staticLabel: "Enter page numbers (comma-separated) and click OK to select the image."
});

// Add a text field to input page numbers
var pageNumbersField = dialog.dialogColumns.add().textEditboxes.add({
editContents: "",
minWidth: 200,
staticLabel: "Page Numbers:"
});

// Show the dialog and capture the result
if (dialog.show() == true) {
// Get the entered page numbers
var pageNumbers = pageNumbersField.editContents;

// Prompt the user to select the image file
var imageFile = File.openDialog("Select the image to replace with");

if (pageNumbers && imageFile) {
var pages = pageNumbers.split(',');

for (var i = 0; i < pages.length; i++) {
var pageNumber = parseInt(pages[i], 10) - 1; // Convert to zero-based index

if (pageNumber >= 0 && pageNumber < doc.pages.length) {
var page = doc.pages[pageNumber];

// Remove all existing images on the page before placing the new one
var images = page.allGraphics;
for (var j = images.length - 1; j >= 0; j--) {
images[j].remove();
}

// Place the new image on the page
var newImage = page.place(imageFile)[0];
newImage.fit(FitOptions.PROPORTIONALLY); // Adjust the image fitting as necessary
} else {
alert("Page number " + (pageNumber + 1) + " is out of range.");
}
}
} else {
alert("Please enter valid page numbers and select an image.");
}
} else {
dialog.destroy();
alert("Action cancelled.");
}

 

4 replies

New Participant
January 28, 2025

im looking for svg images to download . funny fishermen svg. TIA

 

leo.r
Community Expert
January 28, 2025
quote
By @dianna_9432

 

look them up and download.

New Participant
January 28, 2025

dont know how that relates to what im talking about

 

r36058804bwutAuthorCorrect answer
Inspiring
August 23, 2024

I reached to this code by chat GPT , works as a charm

----------------------------------------------------------------------------------

var doc = app.activeDocument;

// Create the main dialog
var dialog = app.dialogs.add({name: "Replace Images on Selected Pages"});

var result = dialog.dialogColumns.add().staticTexts.add({
staticLabel: "Enter page numbers (comma-separated) and click OK to select the image."
});

// Add a text field to input page numbers
var pageNumbersField = dialog.dialogColumns.add().textEditboxes.add({
editContents: "",
minWidth: 200,
staticLabel: "Page Numbers:"
});

// Show the dialog and capture the result
if (dialog.show() == true) {
// Get the entered page numbers
var pageNumbers = pageNumbersField.editContents;

// Prompt the user to select the image file
var imageFile = File.openDialog("Select the image to replace with");

if (pageNumbers && imageFile) {
var pages = pageNumbers.split(',');

for (var i = 0; i < pages.length; i++) {
var pageNumber = parseInt(pages[i], 10) - 1; // Convert to zero-based index

if (pageNumber >= 0 && pageNumber < doc.pages.length) {
var page = doc.pages[pageNumber];

// Remove all existing images on the page before placing the new one
var images = page.allGraphics;
for (var j = images.length - 1; j >= 0; j--) {
images[j].remove();
}

// Place the new image on the page
var newImage = page.place(imageFile)[0];
newImage.fit(FitOptions.PROPORTIONALLY); // Adjust the image fitting as necessary
} else {
alert("Page number " + (pageNumber + 1) + " is out of range.");
}
}
} else {
alert("Please enter valid page numbers and select an image.");
}
} else {
dialog.destroy();
alert("Action cancelled.");
}

 

Robert at ID-Tasker
Brainiac
August 23, 2024

I was under the impression that you need something more sophisticated 😉 - relink to a new version with the same name - not just delete and place a random, new file - which IDT could do as well. 

 

You could do the same manually - select bunch of images and then click through Pages to replace.

 

Or if you have to fill consecutive pages - you could use Image Catalog script included with InDesign. 

 

Inspiring
August 23, 2024

I don't want to select pages manually because each time i relink , a box apear to let me choose the image that i want to replace

m1b
Community Expert
August 23, 2024

Hi @r36058804bwut, it will make things easy if you post a sample indesign document with just a few pages, BEFORE and another document AFTER the script is complete. That way we can see exactly what you expect to be done.

- Mark

Inspiring
August 23, 2024

Hi  m1b

There are 2 files , each consist of 10 pages , that What I want from the script

There are certain images only I want to relink but I want automatically by script not manual beacause the main file contains 400 pages

Thanks

Robert at ID-Tasker
Brainiac
August 23, 2024

Iam working on pc , but i want to know how much is the full version ?


quote

Iam working on pc , but i want to know how much is the full version ?


By @r36058804bwut

 

I sell tokens - monthly and weekly - so you pay when you need to use it - kind of "pay as you go". 

 

It's still in beta stage - so there is no official pricelist. But if you take into consideration, what it can do and how much time it can save - I'm practically giving it for free.