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

Re-link lots of images? Indesign CS3

New Here ,
Apr 17, 2008 Apr 17, 2008
Hi - I posted this in the indesign forum and it was suggested to look here. I've had a quick look for a solution but thought I'd post aswell.

"Because I've resaved a load of jpegs to psds the links are now broken.

Is it possible to relink them all without doing each one manually?

The update link option is greyed out. All the psds are in the same folder. "

Thanks again
TOPICS
Scripting
15.0K
Translate
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
Valorous Hero ,
Aug 25, 2008 Aug 25, 2008
Hi Christoph,

Thank you for the response. I like your idea about suffixes; maybe Ill add this feature to the script some day.

>One peculiarity: at least on my station I get »One file has been relinked.« even if a lot more files have actually been relinked.

Ill recheck this again. Do you have the latest version of the script 10.1?

Kasyan
Translate
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 ,
Aug 25, 2008 Aug 25, 2008
Yes, I have just downloaded »Update path names in links 10-1.jsx« today.
Its no biggie anway, but You seem to be a perfectionist, so I thought Id mention it.
Translate
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
New Here ,
Aug 26, 2008 Aug 26, 2008
Hi Kasyan

I've learned so much from here - thank you for your time and effort you have put into helping everyone

I had been struggling with the DOM within InDesign - i had managed to write a .jsx to iterate through every text box of every page and gather all the text into a single variable (for me this was an improvement on the export text). Then i saw this page and your posts opened my eyes to the automation of image tasks

One thing i cannot work out though (i cant find anywhere) - is it possible to rename the images on the hard disk themselves via the script - rather than just the links?

I don't need any lengthy code - just a snippit of code that would show me how to rename the physical images themselves

For example:
An InDesign document may have 3 pages and on each page may exist a few pics. These could all have obscure names, but we require the script to iterate through each page, create a tidy, unique picture identifier PAGE_001_image01.tif, PAGE_001_imageB02.tif, PAGE_002_image01.tif, PAGE_002_image02.tif, PAGE_002_image03.tif. In order to do this i would need to be able to update the link within InDesign (very easy, thanks to you) and the files themselves

Sorry for the lengthy explanation

Regards
Duncan
Translate
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
Valorous Hero ,
Aug 26, 2008 Aug 26, 2008
Hi Duncan,

Surely it’s possible. I just reinstalled the system on my home computer and haven’t installed Indesing yet, so I wrote this code in Incopy, but it should work in Indesing too. I’ll test it later at work today.

Kasyan
------------------------------------------


var myDoc = app.activeDocument;
var myImages = myDoc.allGraphics;
var myPages = myDoc.pages;
// If the document doesn't contain any images, give alert and exit
if (myImages.length == 0) {
alert("This document doesn't contain any images.", "Script will be terminated");
exit();
}

for (var p = 0; p < myPages.length; p++) {
var myPageNumber = pagenum(myPages

.name);
for (i = myImages.length-1; i >= 0 ; i--) {
var myLink = myImages.itemLink;
var myImageCounter = i + 1;
var myImageNumber = pagenum(myImageCounter);
var myOldLinkName = myLink.name;
// I assume that all extensions consist of 3 characters
var myExtension = myOldLinkName.substr(-4, 4);
var myNewLinkName = "PAGE_" + myPageNumber + "_image" + myImageNumber + myExtension;
var myOldImageFile = new File (myLink.filePath);
var myOldPath = myOldImageFile.toString();
var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);
myOldImageFile.rename(myNewPath);
myLink.relink (myOldImageFile);
myLink.update();
}
}

function pagenum(myNumber){
if (myNumber >= 1 && myNumber <= 9)
{
x = "0" + "0" + myNumber;
}
else if (myNumber >= 10 && myNumber <= 99)
{
x = "0" + myNumber;
}
else if (myNumber >= 100 && myNumber <= 999)
{
x = myNumber;
}
return x
}

Translate
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
Valorous Hero ,
Aug 27, 2008 Aug 27, 2008
Oops! I just tested my previous script and found a mistake, dont use it. Sorry, here is a new version. It works on PC in CS3, but on Mac doesnt I dont know why yet.
//---------------------------------
var myDoc = app.activeDocument;

var myPages = myDoc.pages;

for (var p = 0; p < myPages.length; p++) {
var myPageNumber = pagenum(myPages

.name);
var myImages = myPages

.allGraphics;
for (i = myImages.length-1; i >= 0 ; i--) {
var myLink = myImages.itemLink;
var myImageCounter = i + 1;
var myImageNumber = pagenum(myImageCounter);
var myOldLinkName = myLink.name;
// I assume that all extensions consist of 3 characters
var myExtension = myOldLinkName.substr(-4, 4);
var myNewLinkName = "PAGE_" + myPageNumber + "_image" + myImageNumber + myExtension;
var myOldImageFile = new File (myLink.filePath);
var myOldPath = myOldImageFile.toString();
var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);
myOldImageFile.rename(myNewPath);
myLink.relink (myOldImageFile);
myLink.update();
}
}

function pagenum(myNumber){
if (myNumber >= 1 && myNumber <= 9)
{
x = "0" + "0" + myNumber;
}
else if (myNumber >= 10 && myNumber <= 99)
{
x = "0" + myNumber;
}
else if (myNumber >= 100 && myNumber <= 999)
{
x = myNumber;
}
return x
}

Translate
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
Valorous Hero ,
Aug 27, 2008 Aug 27, 2008
Aha! Now I see why it doesnt work on Mac: instead of
myOldImageFile.rename(myNewPath);
it should be
myOldImageFile.rename(myNewLinkName);
because newName should be file name, with no path information.
However it is strange that it worked on PC.
Here a new version again:
//-----------------------------------------
var myDoc = app.activeDocument;

var myPages = myDoc.pages;

for (var p = 0; p < myPages.length; p++) {
var myPageNumber = pagenum(myPages

.name);
var myImages = myPages

.allGraphics;
for (i = myImages.length-1; i >= 0 ; i--) {
var myLink = myImages.itemLink;
var myImageCounter = i + 1;
var myImageNumber = pagenum(myImageCounter);
var myOldLinkName = myLink.name;
// I assume that all extensions consist of 3 characters
var myExtension = myOldLinkName.substr(-4, 4);
var myNewLinkName = "PAGE_" + myPageNumber + "_image" + myImageNumber + myExtension;
var myOldImageFile = new File (myLink.filePath);
var myOldPath = myOldImageFile.toString();
var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);
myOldImageFile.rename(myNewLinkName);
myLink.relink (myOldImageFile);
myLink.update();
}
}

function pagenum(myNumber){
if (myNumber >= 1 && myNumber <= 9)
{
x = "0" + "0" + myNumber;
}
else if (myNumber >= 10 && myNumber <= 99)
{
x = "0" + myNumber;
}
else if (myNumber >= 100 && myNumber <= 999)
{
x = myNumber;
}
return x
}

Translate
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
New Here ,
Aug 28, 2008 Aug 28, 2008
Hi Kasyan

Thank you so much - i am so impressed

I have been dreaming of being able to do this for quite some time, and you have single-handedly made it possible

I do use a Mac and was baffled why the previous script didn't work - the script looked like it should work (i was playing around for some time trying to work out why not, but i was just not knowledgeable enough to make it work)

However, this revised script is PERFECT! My head is spinning with the possibilities of this scripting. I have been programming in Perl for approx. 10 years and am only just getting into OO methodology. This then opened up my understanding of AS 3 within Flash. This made C more understandable. And Java. And now, thanks to you, i am getting to grips with scripting Adobe's applications. I have already managed to tackle many labourious tasks with scripting techniques, rather than manually.

I get the feeling that so many people are missing out on some serious power offered by scripting the applications; i don't know a single person who exploits this - and probably are ill aware of what they are missing out on.

I assure you that this is incredibly interesting to me, and i am going to study your script in depth until i know it back-to-front. This is the only way i feel comfortable.

Thanks again Kasyan - you are very kind

Regards
Duncan
Translate
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
New Here ,
Sep 08, 2008 Sep 08, 2008
Wonderful! Thank you, thank you!
Translate
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
New Here ,
Sep 13, 2008 Sep 13, 2008
Hi Kasyan

I have been playing around with this for some time now - although i am having problems with any image used more than once

I am banging my head against a wall here - once the update is done on any first instance of an image, then subsequent ones fail [ i guess due to the fact that the link is now broken ]

I have incorporated a check for an active / broken link, allowing different actions to be performed, and an Object to remember the revised link of pre-processed files, and a regular expression steal the characters after the last full stop [ in case the file extensions are 4 characters, for example ]

I would be very grateful if you could help me with this

Thank you!

var myDoc = app.activeDocument;
var myImages = myDoc.allGraphics;
var seen = Object;
var messageCounter = 0;

for (var i = myImages.length-1; i >= 0; i--) {
var myOldLink = myImages.itemLink;
var myOldLinkName = myOldLink.name;
if (seen[myOldLinkName]) {
//alert("SEEN\n" + myOldLinkName);
} else {
//alert("FIRST SEEN\n" + myOldLinkName);
seen[myOldLinkName] = 1;
}
}

var myPages = myDoc.pages;
for (var p = 0; p < myPages.length; p++) {
var myPageNumber = zeros3(myPages

.name);
var myImageNumber;
var imagesPerPageCounter = 1;
//alert("PAGE " + myPageNum);

myImages = myPages

.allGraphics;
for (i = myImages.length-1; i >= 0; i--) {
myOldLink = myImages.itemLink; // [ object ]
myOldLinkName = myOldLink.name;
myImageNumber = zeros2(imagesPerPageCounter);
var myFileExtensionRegEx = /\.[^.]+$/g;
var imageExtension = myOldLinkName.match(myFileExtensionRegEx);
var whereHasTheLinkGone = Object;
var whatWasTheLinkName = Object;

if (myOldLink.status == 1852797549) { // *** LINK O.K. ***

myNewLinkName = 'PREPENDED_P' + myPageNumber + "_image" + myImageNumber + imageExtension;

var myOldImageFile = new File(myOldLink.filePath);
var myOldPath = myOldImageFile.toString();
var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);

myOldImageFile.rename(myNewLinkName);
myOldLink.relink(myOldImageFile);
myOldLink.update();

whereHasTheLinkGone[myOldLinkName] = myOldImageFile;
whatWasTheLinkName[myOldLinkName] = myNewLinkName;

feedback("LINK O.K. : " + myOldLinkName + "\nmyOldImageFile:" + myOldImageFile + "\n\nmyOldPath:" + myOldPath + "\n\nmyNewPath:" + myNewPath + "\n\nimagesPerPageCounter:" + imagesPerPageCounter + "\n\nwhereHasTheLinkGone:" + whereHasTheLinkGone[myOldLinkName] + "\n\n" + whatWasTheLinkName[myOldLinkName]);

imagesPerPageCounter++;

} else { // LINK BROKEN

// ********** HOW CAN I LINK TO THE RENAMED IMAGE HERE ? **********

feedback("LINK MISSING : " + myOldLinkName + "\nmyOldImageFile:" + myOldImageFile + "\n\nmyOldPath:" + myOldPath + "\n\nmyNewPath:" + myNewPath + "\n\nimagesPerPageCounter:" + imagesPerPageCounter + "\n\nwhereHasTheLinkGone:" + whereHasTheLinkGone[myOldLinkName] + "\n\n" + whatWasTheLinkName[myOldLinkName]);

}
}
}

function zeros3(myNumber) {
if (myNumber >= 1 && myNumber <= 9) {
x = "0" + "0" + myNumber;
}
else if (myNumber >= 10 && myNumber <= 99) {
x = "0" + myNumber;
}
else if (myNumber >= 100 && myNumber <= 999) {
x = myNumber;
}
return x;
}

function zeros2(myNumber) {
if (myNumber >= 1 && myNumber <= 9) {
x = "0" + myNumber;
}
else if (myNumber >= 10 && myNumber <= 99) {
x = myNumber;
}
return x;
}

function feedback(message) {
if (messageCounter++ < 10) {
alert(message);
}
}

Duncan

Translate
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
New Here ,
Sep 13, 2008 Sep 13, 2008
Hi Kasyan

I have been playing around with this for some time now - although i am having problems with any image used more than once

I am banging my head against a wall here - once the update is done on any first instance of an image, then subsequent ones fail [ i guess due to the fact that the link is now broken ]

I have incorporated a check for an active / broken link, allowing different actions to be performed, and an Object to remember the revised link of pre-processed files, and a regular expression steal the characters after the last full stop [ in case the file extensions are 4 characters, for example ]

I would be very grateful if you could help me with this

Thank you!


var myDoc = app.activeDocument;
var myImages = myDoc.allGraphics;
var seen = Object;
var messageCounter = 0;

for (var i = myImages.length-1; i >= 0; i--) {
var myOldLink = myImages.itemLink;
var myOldLinkName = myOldLink.name;
if (seen[myOldLinkName]) {
//alert("SEEN\n" + myOldLinkName);
} else {
//alert("FIRST SEEN\n" + myOldLinkName);
seen[myOldLinkName] = 1;
}
}

var myPages = myDoc.pages;
for (var p = 0; p < myPages.length; p++) {
var myPageNumber = zeros3(myPages

.name);
var myImageNumber;
var imagesPerPageCounter = 1;
//alert("PAGE " + myPageNum);

myImages = myPages

.allGraphics;
for (i = myImages.length-1; i >= 0; i--) {
myOldLink = myImages.itemLink; // [ object ]
myOldLinkName = myOldLink.name;
myImageNumber = zeros2(imagesPerPageCounter);
var myFileExtensionRegEx = /\.[^.]+$/g;
var imageExtension = myOldLinkName.match(myFileExtensionRegEx);
var whereHasTheLinkGone = Object;
var whatWasTheLinkName = Object;

if (myOldLink.status == 1852797549) { // *** LINK O.K. ***

myNewLinkName = 'PREPENDED_P' + myPageNumber + "_image" + myImageNumber + imageExtension;

var myOldImageFile = new File(myOldLink.filePath);
var myOldPath = myOldImageFile.toString();
var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);

myOldImageFile.rename(myNewLinkName);
myOldLink.relink(myOldImageFile);
myOldLink.update();

whereHasTheLinkGone[myOldLinkName] = myOldImageFile;
whatWasTheLinkName[myOldLinkName] = myNewLinkName;

feedback("LINK O.K. : " + myOldLinkName + "\nmyOldImageFile:" + myOldImageFile + "\n\nmyOldPath:" + myOldPath + "\n\nmyNewPath:" + myNewPath + "\n\nimagesPerPageCounter:" + imagesPerPageCounter + "\n\nwhereHasTheLinkGone:" + whereHasTheLinkGone[myOldLinkName] + "\n\n" + whatWasTheLinkName[myOldLinkName]);

imagesPerPageCounter++;

} else { // LINK BROKEN

// ********** HOW CAN I LINK TO THE RENAMED IMAGE HERE ? **********

feedback("LINK MISSING : " + myOldLinkName + "\nmyOldImageFile:" + myOldImageFile + "\n\nmyOldPath:" + myOldPath + "\n\nmyNewPath:" + myNewPath + "\n\nimagesPerPageCounter:" + imagesPerPageCounter + "\n\nwhereHasTheLinkGone:" + whereHasTheLinkGone[myOldLinkName] + "\n\n" + whatWasTheLinkName[myOldLinkName]);

}
}
}

function zeros3(myNumber) {
if (myNumber >= 1 && myNumber <= 9) {
x = "0" + "0" + myNumber;
}
else if (myNumber >= 10 && myNumber <= 99) {
x = "0" + myNumber;
}
else if (myNumber >= 100 && myNumber <= 999) {
x = myNumber;
}
return x;
}

function zeros2(myNumber) {
if (myNumber >= 1 && myNumber <= 9) {
x = "0" + myNumber;
}
else if (myNumber >= 10 && myNumber <= 99) {
x = myNumber;
}
return x;
}

function feedback(message) {
if (messageCounter++ < 10) {
alert(message);
}
}



Duncan
Translate
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
New Here ,
Sep 13, 2008 Sep 13, 2008
Hi Kasyan

I have been playing around with this for some time now - although i am having problems with any image used more than once

I am banging my head against a wall here - once the update is done on any first instance of an image, then subsequent ones fail [ i guess due to the fact that the link is now broken ]

I have incorporated a check for an active / broken link, allowing different actions to be performed, and an Object to remember the revised link of pre-processed files, and a regular expression steal the characters after the last full stop [ in case the file extensions are 4 characters, for example ]

I would be very grateful if you could help me with this

Thank you!

var myDoc = app.activeDocument;

var myImages = myDoc.allGraphics;
var seen = Object;
var messageCounter = 0;

for (var i = myImages.length-1; i >= 0; i--) {
var myOldLink = myImages.itemLink;
var myOldLinkName = myOldLink.name;
if (seen[myOldLinkName]) {
//alert("SEEN\n" + myOldLinkName);
} else {
//alert("FIRST SEEN\n" + myOldLinkName);
seen[myOldLinkName] = 1;
}
}

var myPages = myDoc.pages;
for (var p = 0; p < myPages.length; p++) {
var myPageNumber = zeros3(myPages

.name);
var myImageNumber;
var imagesPerPageCounter = 1;
//alert("PAGE " + myPageNum);

myImages = myPages

.allGraphics;
for (i = myImages.length-1; i >= 0; i--) {
myOldLink = myImages.itemLink; // [ object ]
myOldLinkName = myOldLink.name;
myImageNumber = zeros2(imagesPerPageCounter);
var myFileExtensionRegEx = /\.[^.]+$/g;
var imageExtension = myOldLinkName.match(myFileExtensionRegEx);
var whereHasTheLinkGone = Object;
var whatWasTheLinkName = Object;

if (myOldLink.status == 1852797549) { // *** LINK O.K. ***

myNewLinkName = 'PREPENDED_P' + myPageNumber + "_image" + myImageNumber + imageExtension;

var myOldImageFile = new File(myOldLink.filePath);
var myOldPath = myOldImageFile.toString();
var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);

myOldImageFile.rename(myNewLinkName);
myOldLink.relink(myOldImageFile);
myOldLink.update();

whereHasTheLinkGone[myOldLinkName] = myOldImageFile;
whatWasTheLinkName[myOldLinkName] = myNewLinkName;

feedback("LINK O.K. : " + myOldLinkName + "\nmyOldImageFile:" + myOldImageFile + "\n\nmyOldPath:" + myOldPath + "\n\nmyNewPath:" + myNewPath + "\n\nimagesPerPageCounter:" + imagesPerPageCounter + "\n\nwhereHasTheLinkGone:" + whereHasTheLinkGone[myOldLinkName] + "\n\n" + whatWasTheLinkName[myOldLinkName]);

imagesPerPageCounter++;

} else { // LINK BROKEN

// ********** HOW CAN I LINK TO THE RENAMED IMAGE HERE ? **********

feedback("LINK MISSING : " + myOldLinkName + "\nmyOldImageFile:" + myOldImageFile + "\n\nmyOldPath:" + myOldPath + "\n\nmyNewPath:" + myNewPath + "\n\nimagesPerPageCounter:" + imagesPerPageCounter + "\n\nwhereHasTheLinkGone:" + whereHasTheLinkGone[myOldLinkName] + "\n\n" + whatWasTheLinkName[myOldLinkName]);

}
}
}

function zeros3(myNumber) {
if (myNumber >= 1 && myNumber <= 9) {
x = "0" + "0" + myNumber;
}
else if (myNumber >= 10 && myNumber <= 99) {
x = "0" + myNumber;
}
else if (myNumber >= 100 && myNumber <= 999) {
x = myNumber;
}
return x;
}

function zeros2(myNumber) {
if (myNumber >= 1 && myNumber <= 9) {
x = "0" + myNumber;
}
else if (myNumber >= 10 && myNumber <= 99) {
x = myNumber;
}
return x;
}

function feedback(message) {
if (messageCounter++ < 10) {
alert(message);
}
}



Duncan
Translate
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
New Here ,
Sep 13, 2008 Sep 13, 2008
Hi Kasyan

I have been playing around with this for some time now - although i am having problems with any image used more than once

I am banging my head against a wall here - once the update is done on any first instance of an image, then subsequent ones fail [ i guess due to the fact that the link is now broken ]

I have incorporated a check for an active / broken link, allowing different actions to be performed, and an Object to remember the revised link of pre-processed files, and a regular expression steal the characters after the last full stop [ in case the file extensions are 4 characters, for example ]

I would be very grateful if you could help me with this

Thank you!

var myDoc = app.activeDocument;

var myImages = myDoc.allGraphics;
var seen = Object;
var messageCounter = 0;

for (var i = myImages.length-1; i >= 0; i--) {
var myOldLink = myImages.itemLink;
var myOldLinkName = myOldLink.name;
if (seen[myOldLinkName]) {
//alert("SEEN\n" + myOldLinkName);
} else {
//alert("FIRST SEEN\n" + myOldLinkName);
seen[myOldLinkName] = 1;
}
}

var myPages = myDoc.pages;
for (var p = 0; p < myPages.length; p++) {
var myPageNumber = zeros3(myPages

.name);
var myImageNumber;
var imagesPerPageCounter = 1;
//alert("PAGE " + myPageNum);

myImages = myPages

.allGraphics;
for (i = myImages.length-1; i >= 0; i--) {
myOldLink = myImages.itemLink; // [ object ]
myOldLinkName = myOldLink.name;
myImageNumber = zeros2(imagesPerPageCounter);
var myFileExtensionRegEx = /\.[^.]+$/g;
var imageExtension = myOldLinkName.match(myFileExtensionRegEx);
var whereHasTheLinkGone = Object;
var whatWasTheLinkName = Object;

if (myOldLink.status == 1852797549) { // *** LINK O.K. ***

myNewLinkName = 'PREPENDED_P' + myPageNumber + "_image" + myImageNumber + imageExtension;

var myOldImageFile = new File(myOldLink.filePath);
var myOldPath = myOldImageFile.toString();
var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);

myOldImageFile.rename(myNewLinkName);
myOldLink.relink(myOldImageFile);
myOldLink.update();

whereHasTheLinkGone[myOldLinkName] = myOldImageFile;
whatWasTheLinkName[myOldLinkName] = myNewLinkName;

feedback("LINK O.K. : " + myOldLinkName + "\nmyOldImageFile:" + myOldImageFile + "\n\nmyOldPath:" + myOldPath + "\n\nmyNewPath:" + myNewPath + "\n\nimagesPerPageCounter:" + imagesPerPageCounter + "\n\nwhereHasTheLinkGone:" + whereHasTheLinkGone[myOldLinkName] + "\n\n" + whatWasTheLinkName[myOldLinkName]);

imagesPerPageCounter++;

} else { // LINK BROKEN

// ********** HOW CAN I LINK TO THE RENAMED IMAGE HERE ? **********

feedback("LINK MISSING : " + myOldLinkName + "\nmyOldImageFile:" + myOldImageFile + "\n\nmyOldPath:" + myOldPath + "\n\nmyNewPath:" + myNewPath + "\n\nimagesPerPageCounter:" + imagesPerPageCounter + "\n\nwhereHasTheLinkGone:" + whereHasTheLinkGone[myOldLinkName] + "\n\n" + whatWasTheLinkName[myOldLinkName]);

}
}
}

function zeros3(myNumber) {
if (myNumber >= 1 && myNumber <= 9) {
x = "0" + "0" + myNumber;
}
else if (myNumber >= 10 && myNumber <= 99) {
x = "0" + myNumber;
}
else if (myNumber >= 100 && myNumber <= 999) {
x = myNumber;
}
return x;
}

function zeros2(myNumber) {
if (myNumber >= 1 && myNumber <= 9) {
x = "0" + myNumber;
}
else if (myNumber >= 10 && myNumber <= 99) {
x = myNumber;
}
return x;
}

function feedback(message) {
if (messageCounter++ < 10) {
alert(message);
}
}



Duncan
Translate
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
Valorous Hero ,
Sep 14, 2008 Sep 14, 2008
Hi Duncan,

Here is a new version of the script, which deals with links placed more then once and extensions consisting of any number of characters. It’s not totally tested yet, so let me know if it works for you.

Kasyan
//------------------------------


#target indesign-5.0
var myDoc = app.activeDocument;
var myPages = myDoc.pages;
var myAllLinks = myDoc.links;
var myProcessedImages = new Array;

for (var p = 0; p < myPages.length; p++) {
var myPageNumber = pagenum(myPages

.name);
var myImages = myPages

.allGraphics;
var myImageCounter = 0; // set the counter of images to zero at start of each loop
for (i = myAllLinks.length-1; i >= 0 ; i--) {
var myLink = myAllLinks;
var myOldLinkName = myLink.name;
var myOldImageFile = new File (myLink.filePath);
var myOldPath = myOldImageFile.toString();
if (myIsInArray(myLink, myProcessedImages) == false) {
var myLinkUsage = LinkUsage(myLink);
myImageCounter ++;
var myImageNumber = pagenum(myImageCounter);
// now I assume that all extensions may consist of any number of characters
var myExtension = myOldLinkName.substr((myOldLinkName.lastIndexOf( "." )));
var myNewLinkName = "PAGE_" + myPageNumber + "_image" + myImageNumber + myExtension;
var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);
myOldImageFile.rename(myNewLinkName);
if (myLinkUsage == 0) {
myLink.relink (myNewFile);
myLink.update();
myProcessedImages.push(myLink);
}
else {
var myMultyPlacedLinks = multyPlacedLinks(myLink);
for (k = myMultyPlacedLinks.length-1; k >= 0 ; k--) {
if (!myOldImageFile.exists){
break;
}
myMultyPlacedLinks.relink (myOldImageFile);
myMultyPlacedLinks.update();
}
myProcessedImages.push(myLink);
}
}
}
}
function pagenum(myNumber){
if (myNumber >= 1 && myNumber <= 9)
{
x = "0" + "0" + myNumber;
}
else if (myNumber >= 10 && myNumber <= 99)
{
x = "0" + myNumber;
}
else if (myNumber >= 100 && myNumber <= 999)
{
x = myNumber;
}
return x
}
function LinkUsage(myLink) {
var myLinkCounter = 0;
for (var myCounter = 0; myCounter < myAllLinks.length; myCounter++) {
if (myLink.filePath == myAllLinks[myCounter].filePath) {
myLinkCounter += 1;
}
}
return myLinkCounter
}
function multyPlacedLinks(myLink) {
var myMultyImages = new Array();
for (var myCounter = 0; myCounter < myAllLinks.length; myCounter++) {
if (myLink.filePath == myAllLinks[myCounter].filePath) {
myMultyImages.push(myAllLinks[myCounter]);
}
}
return myMultyImages;
}
function myIsInArray(myLink, myArray) {
var theResult = false;
for (myCounter = 0; myCounter < myArray.length; myCounter ++) {
if (myArray[myCounter].filePath == myLink.filePath) {
theResult = true;
break;
}
}
return theResult;
}

Translate
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
New Here ,
Sep 16, 2008 Sep 16, 2008
Hi Kasyan

Wow! I must have spent about 20 hours trying to solve this. The script worked beautifully.

I've been programming for fun since i was 12 - and now i am 39. I very rarely bump into anyone that impresses me - and i am certainly impressed with your understanding of this. I really don't know what you gain from spending your time helping people with their problems, but i am really grateful for the time you have spent helping me.

As i mentioned in a previous post, i do not want you to think i want you to do my work for me - i have spent hours going over every line of your script and plucking them apart until i finally understood how it all worked. It finally grasped it today - i think - and have included my version (a bit like a homework project!). If i have managed to understand your teachings, i will have a whole arsenal of tools to attack InDesign and automate all sorts of stuff in the future. And this could save me days. For this i am truly appreciative.

I would be (very) grateful for any comments on the script if you have any!

var myPages = app.activeDocument.pages;

var myProcessed = Object;

for (var p = 0; p < myPages.length; p++) {

var myPageNumber = pad000(myPages

.name);
var myImages = myPages

.allGraphics;
var myImageCounter = 0;

for (i = myImages.length-1; i >= 0 ; i--) {

myImageCounter++;

var myLink = myImages.itemLink;
var myOldLinkName = myLink.name;

if (! myProcessed[myOldLinkName]) {
var myImageNumber = pad000(myImageCounter);
var myExtension = myOldLinkName.substr(myOldLinkName.lastIndexOf( "." ));
var myNewLinkName = "PAGE_" + myPageNumber + "_image" + myImageNumber + myExtension;
var myOldImageHDfile = new File(myLink.filePath);
myOldImageHDfile.rename(myNewLinkName);
myProcessed[myOldLinkName] = myOldImageHDfile;
}
myLink.relink(myProcessed[myOldLinkName]);
myLink.update();

}
}

function pad000(myNumber) {
if (myNumber >= 1 && myNumber <= 9) {
x = "0" + "0" + myNumber;
} else if (myNumber >= 10 && myNumber <= 99) {
x = "0" + myNumber;
} else if (myNumber >= 100 && myNumber <= 999) {
x = myNumber;
}
return x;
}



Kind regards
Duncan
Translate
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
Valorous Hero ,
Sep 17, 2008 Sep 17, 2008
Nice code, Duncan. Its much more concise than mine. But never stop at what has been accomplished e.g. Id put in a function to check for missing/modified links at start of the script:


function checkLinkNormal(){
for(var myCounter = 0; myCounter < myDoc.links.length; myCounter++){
var myLink = myDoc.links[myCounter];
if (myLink.status != LinkStatus.normal){
if (myLink.status == LinkStatus.linkOutOfDate){
myLink.show();
alert ("This link is modified");
myProblems++;
}
else if (myLink.status == LinkStatus.linkMissing){
myLink.show();
alert ("This link is missing.");
myProblems++;
}
else if (myLink.status == LinkStatus.linkEmbedded){
myLink.show();
alert ("This link is embedded.");
myProblems++;
}
exit();
}
}
}


>I really don't know what you gain from spending your time helping people with their problems

Scripting is my hobby, for me it is mental gymnastics, like playing chess. Im not programmer by background and a few years ago I couldnt even imagine that I would busy oneself with it. BTW Im 39 too. When I was making my baby steps in scripting, this forum helped me a lot to solve my problems, so now I try to help others as far as I can.

Kasyan
Translate
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
New Here ,
Sep 25, 2008 Sep 25, 2008
Hi Kasyan

(Apologies for not replying sooner - i have been away for a few days)

Thank you for your reply - at least now i can be confident that i am on the right track. I hope that by pulling your script apart and seeing how you built it has given me the building blocks i need to tackle future problems. I (personally) found the biggest headache the DOM - i have been scripting in Perl for 10 or so years, but i have never had the ability to script an application before. It opens up so many doors it is quite bewildering! PhotoShop, Illustrator ...

Can i please ask where you found the information on the DOM - i found the web to be a really difficult place to find the information on this. I ended up with several PDF's but none really had the depth needed. I was also interested as to why you started scripting? I wish more people would get into it. I can honestly say that the vast majority of people i have met over 19 years designing/typesetting who are not even aware that it is possible - let alone attempting to write even a basic script. A shame i think.

I like your last addition to the script by the way

Thanks again for all your help

Regards
Duncan
Translate
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
Valorous Hero ,
Sep 26, 2008 Sep 26, 2008
Hi Duncan,

> Can i please ask where you found the information on the DOM - i found the web to be a really difficult place to find the information on this.

To find all the information about object model I use OMV in ESTK, or HTML Help file called InDesign Script Model.chm its quicker and more easy-to-use. If you are interested you can download it from here: http://toolbox.rudtp.ru/download.php?fileid=229.

I can give you my favorite links.
First of all, check out this page on Adobe site (Scripting resources section) and make sure to download the supporting Scripting Guide scripts http://wwwimages.adobe.com/www.adobe.com/products/indesign/scripting/downloads/indesign_cs3_guide_scripts.zip it contains examples of scripts, covering majority of aspects of ID scripting. In my opinion the best way to study scripting is to take an example and examine it.
http://www.adobe.com/products/indesign/scripting/index.html

Also I strongly recommend you to read Dave Saunders blog:
http://www.jsid.blogspot.com/
and browse this site:
http://www.pdsassoc.com/

And be sure to visit Bob Stuckys site http://www.creativescripting.net/ Id like to draw your attention to his terrific script library.

Whenever you start writing a script, take a look at what other scripters did; its quite possible that somebody has already done something similar and you can use it as a basis for your own script.
So take a look at these sites:

Adobe Exchange:
http://www.adobe.com/cfusion/exchange/index.cfm?s=5&from=1&o=desc&cat=224&l=-1&event=productHome&exc=19
Peter Kahrels site:
http://www.kahrel.plus.com/indesignscripts.html
Here is a couple of Russian sites from which you can download some interesting scripts, even though you dont understand Russian:
http://toolbox.rudtp.ru/index.php?id=184&lang=JavaScript
http://indesign.dezigner.ru/RealScripts.html

>I was also interested as to why you started scripting?

To tell the truth, I never thought that I would busy myself with it. And when I, for the first time, downloaded a more than 1800 page scripting reference, it occurred to me that it would be the last thing in my life to concern myself with.
I began with using existing scripts then I started remaking them, then I was carried away by scripting and embarked on writing my own scripts. The effect is tremendous I work in a weekly magazine and now we are able to make an issue (in average 144176 pages) for 2 days. But there was a side effect as well: our department endured a 50% stuff reduction. I was lucky, still working.

Kasyan
Translate
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
New Here ,
Oct 30, 2008 Oct 30, 2008
Hi Kasyan

Thank you ever so much for all this info - very useful indeed

I have also purchased a couple of books - Photoshop & Indesign javascript scripting guides [ both CS2 though ]

Thanks again for all your help

Regards,
Duncan
Translate
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 ,
Oct 30, 2008 Oct 30, 2008
Adding to Kasyan's extensive list, why not see http://www.adobeforums.com/webx/.3bbf275d.59b6defe -- it's for Javascript, it's for CS3, it's for free.

The CHM mentioned is similar to the one above, but in
i my
version just about everything possible (and sometime impossible) is hyperlinked together.
Translate
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
New Here ,
Oct 30, 2008 Oct 30, 2008
The script above is exactly what i've been looking for a while now.

I've just played with the script that renames and relinks images. The image counter is successful counting the images and relink is perfect.
Just the page numbering does not work - all items are still called "page 001" even though they are many more images on many more pages.
Maybe it's because I'm on CS3 german edition?

Please advice - i'm a scripting nuuuuuub.

Best,
s
Translate
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 ,
Oct 30, 2008 Oct 30, 2008
That's not so hard ;-)

>var myPageNumber = pad000(myPages

.name);

mypages

.name is a string ... Now, you don't want to use 'index' because this will work for documents numbered 1 to xx, but not for any other numbering scheme, such as starting with another number, having roman numerals, having a prefix "Chapter 1:5" etc. (which is, after all, why it's implemented as a string).

If you want the zero padding and always use 'regular' numbered pages, this would work:

>var myPageNumber = pad000(parseInt(myPages

.name));

The name that goes in is a string, parseInt converts it to a number, pad000 converts it back to a string (because you 'add' another string to it), and myPageNumber is a string.

Translate
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
New Here ,
Oct 30, 2008 Oct 30, 2008
My Script now looks like this:

#target indesign-5.0
var myDoc = app.activeDocument;
var myPages = myDoc.pages;
var myAllLinks = myDoc.links;
var myProcessedImages = new Array;

for (var p = 0; p < myPages.length; p++) {
var myPageNumber = pad000(parseInt(myPages

.name));
var myImages = myPages

.allGraphics;
var myImageCounter = 0; // set the counter of images to zero at start of each loop
for (i = myAllLinks.length-1; i >= 0 ; i--) {
var myLink = myAllLinks;
var myOldLinkName = myLink.name;
var myOldImageFile = new File (myLink.filePath);
var myOldPath = myOldImageFile.toString();
if (myIsInArray(myLink, myProcessedImages) == false) {
var myLinkUsage = LinkUsage(myLink);
myImageCounter ++;
var myImageNumber = pagenum(myImageCounter);
// now I assume that all extensions may consist of any number of characters
var myExtension = myOldLinkName.substr((myOldLinkName.lastIndexOf( "." )));
var myNewLinkName = "PAGE_" + myPageNumber + "_image" + myImageNumber + myExtension;
var myNewPath = myOldPath.replace(myOldLinkName, myNewLinkName);
myOldImageFile.rename(myNewLinkName);
if (myLinkUsage == 0) {
myLink.relink (myNewFile);
myLink.update();
myProcessedImages.push(myLink);
}
else {
var myMultyPlacedLinks = multyPlacedLinks(myLink);
for (k = myMultyPlacedLinks.length-1; k >= 0 ; k--) {
if (!myOldImageFile.exists){
break;
}
myMultyPlacedLinks.relink (myOldImageFile);
myMultyPlacedLinks.update();
}
myProcessedImages.push(myLink);
}
}
}
}
function pagenum(myNumber){
if (myNumber >= 1 && myNumber <= 9)
{
x = "0" + "0" + myNumber;
}
else if (myNumber >= 10 && myNumber <= 99)
{
x = "0" + myNumber;
}
else if (myNumber >= 100 && myNumber <= 999)
{
x = myNumber;
}
return x
}
function LinkUsage(myLink) {
var myLinkCounter = 0;
for (var myCounter = 0; myCounter < myAllLinks.length; myCounter++) {
if (myLink.filePath == myAllLinks[myCounter].filePath) {
myLinkCounter += 1;
}
}
return myLinkCounter
}
function multyPlacedLinks(myLink) {
var myMultyImages = new Array();
for (var myCounter = 0; myCounter < myAllLinks.length; myCounter++) {
if (myLink.filePath == myAllLinks[myCounter].filePath) {
myMultyImages.push(myAllLinks[myCounter]);
}
}
return myMultyImages;
}
function myIsInArray(myLink, myArray) {
var theResult = false;
for (myCounter = 0; myCounter < myArray.length; myCounter ++) {
if (myArray[myCounter].filePath == myLink.filePath) {
theResult = true;
break;
}
}
return theResult;
}

And now it gives me an error:

pad000 is not a function ... -

Any one an idea?

Best,
S

PS: This forum is so great!!

Translate
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 ,
Oct 30, 2008 Oct 30, 2008
If you search for 'pad000', you can see it's right there at the top, just waiting to add padding zeroes to page numbers. (As it did in the script a few posts earlier.)

Now, looking at the
i bottom,
you can see there is a function for adding zeroes to a number, but it's called 'pageNum'. For some reason the script writer changed its name halfway the posts, and I just read the final version.

Change either of these two to the other name and it'll work.
Translate
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
New Here ,
Oct 30, 2008 Oct 30, 2008
Sorry, but it does not work for me - I'm dumb ...

The error is gone, but it does not change the page number.

When you say this works - can you please copy paste the entire script with the correction and leave some comments in the script?

I'm new as of today to this scripting stuff and feel overwhelmed ...

Best, D
Translate
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
Valorous Hero ,
Oct 30, 2008 Oct 30, 2008
Hi dugie,

I just retested the script (the version posted by Duncun on September 16) and it works: page numbering changes. Send me e-mail to kasyan@business.ua and Ill send you back this script.

Kasyan
Translate
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