Highlighted

JavaScript To Replace Multiple Images With New Images

Contributor ,
Sep 29, 2020

Copy link to clipboard

Copied

Windows 10 64bit or iMac 2019 - both running Adobe CC 2020 apps.

 

I have multiple InDesign files that are about 250 pages each. My client wants me to replace anywhere from 30 - 40 pictures per file with new images. Is there a JavaScript file that can do this? I imagine I would have to enter the existing image file names along with the new file names into such a script, if it exists.

It's only an island if you look at it from the water.
TOPICS
How to, Scripting

Views

75

Likes

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

JavaScript To Replace Multiple Images With New Images

Contributor ,
Sep 29, 2020

Copy link to clipboard

Copied

Windows 10 64bit or iMac 2019 - both running Adobe CC 2020 apps.

 

I have multiple InDesign files that are about 250 pages each. My client wants me to replace anywhere from 30 - 40 pictures per file with new images. Is there a JavaScript file that can do this? I imagine I would have to enter the existing image file names along with the new file names into such a script, if it exists.

It's only an island if you look at it from the water.
TOPICS
How to, Scripting

Views

76

Likes

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
Sep 29, 2020 0
Adobe Community Professional ,
Sep 29, 2020

Copy link to clipboard

Copied

There is the relink panel. You can hold shift to multi-select. Otherwise, yeah, something like: 

 

 

 

var arr = [
   ["oldName.jpg", "full/path/to/newimage.jpg"],
   ["oldName2.pdf", "full/path/to/newName2.pdf"],
   //etc. 
];
var theLink;
var theDoc = app.documents[0];
for (var i =0; i < arr.length; i++) {
   theLink = theDoc.links.itemByName(arr[i][0]);
   theLink.relink(File(arr[i][1]);
}

 

 

 

You'll run into issues, though, if the same link is used multiple times in a doc. 

 

You can also look at this existing relink script: https://indesignsecrets.com/a-script-for-relinking-images.php

Likes

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
Reply
Loading...
Sep 29, 2020 0
Contributor ,
Sep 29, 2020

Copy link to clipboard

Copied

Thanks for your reply! What kind of issue would I run into if the same pic is used multiple times? Won't it just replace all instances of it with the new pic?

It's only an island if you look at it from the water.

Likes

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
Reply
Loading...
Sep 29, 2020 0
Adobe Community Professional ,
Sep 29, 2020

Copy link to clipboard

Copied

Because itemByName will only grab one link. We probably have to iterate through the whole link list instead. Maybe something like this, but could probably use refinement. Note the syntax change from using an array to object: 

 

var theObj = {
   "oldName.jpg": "full/path/to/newimage.jpg",
   "oldName2.pdf": "full/path/to/newName2.pdf",
   //etc. 
};
var theLinks = app.documents[0].links.everyItem().getElements();
for (var i =0; i < theLinks.length; i++) {
   if (theObj.hasOwnProperty(theLinks[i].name)) {
      try { 
            theLinks[i].relink(File(theObj[theLinks[i].name]));
      } catch(e) {}
   }
}

 

Likes

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
Reply
Loading...
Sep 29, 2020 0