Copy link to clipboard
Copied
I know very little about writing scripts, so I'm looking for some help with this.
We use InDesign CC 2014 on Macs to create 30 catalogs, each with thousands of placed/linked images. The problem is that the originally placed images might or might not have file names that match the part numbers they represent (which is the way we currently name the image files) because they are old images and the part numbers have been changed. Because we have had new images created for many of the parts but the files were saved using the new part numbers, I'm looking for a script that will find a part number in the InDesign file (they all have a two-digit prefix then a dash then either five or six digits, then a tab), search within a directory for a file that has the same name as the part number, and replace the existing image that's linked to it with the new one. The new images should all be tiffs, but some might be eps. If there is no new image file, then it should leave the existing linked image as is.
I'm not sure if this is even possible because I'm not sure if a script can determine whether or not an image is linked to text, but it's worth a shot to ask.
I can give someone a sample InDesign file if needed. I'd like to know if this is possible and what it would cost to have it written.
Thanks,
Lloyd
Copy link to clipboard
Copied
If no one can answer my original post, can anyone point me in the right direction to try and find an answer to this problem? I would greatly appreciate it.
Thank you,
Lloyd
Copy link to clipboard
Copied
Can you give me a sample of indesign file?
Copy link to clipboard
Copied
Sure. I can create a couple pages form one of the catalogs. Do you want me to attach it here?
Copy link to clipboard
Copied
Yes, attach bere, Can you give un example off 2 Image old and new Also?
Copy link to clipboard
Copied
Stefano,
I'm not able to attach a file. How should I get it to you?
Thank you for looking at this.
Lloyd
Copy link to clipboard
Copied
Hi, Lloyd
Try to execute this code. If you have only one pair Part Number/Part Image on page, it should work. If layout is more complicated, send me a sample: [Private mail address removed by moderator]
it's best practice to communicate mail addresses with private messages through the forum software.
When logged in just hover over the screen name of a participant and the button "Message" should pop up.
If you are posting your mail address here out in the open the spam bots will grap it easily…
Regards,
.
Regards,
Mitya
filePath=app.activeDocument.fullName.toString().slice(0,-app.activeDocument.name.length);
fgp = app.findGrepPreferences;
app.findGrepPreferences = NothingEnum.NOTHING;
fgp.findWhat = '\\<\\d\\d-\\d+(?=\\t)';
partNumbers=app.activeDocument.findGrep(); // Find all part numbers
for (pn =0;pn<partNumbers.length;pn++) // For each part number...
for (i=0;i<partNumbers[pn].parentTextFrames[0].parentPage.allGraphics.length;i++) { //...take all images on the page, where part number was finded...
fileName=partNumbers[pn].contents;
try { partNumbers[pn].parentTextFrames[0].parentPage.allGraphics.place (new File(filePath+fileName + '.tiff'),false) } catch(_) { //...and try to place new file
try { partNumbers[pn].parentTextFrames[0].parentPage.allGraphics.place (new File(filePath+fileName + '.eps'),false) } catch(_) {}
}
}
Copy link to clipboard
Copied
I got your sample, here is final code. It try to find images in the same folder, where InDesign document is saved. You can edit frist line, if you prefer another place
filePath=Folder (app.activeDocument.fullName.path);
fgp = app.findGrepPreferences;
app.findGrepPreferences = NothingEnum.NOTHING;
fgp.findWhat = '\\<\\d\\d-\\d+(?=\\t)';
partNumbers=app.activeDocument.findGrep(); // Find all part numbers
for (pn =0;pn<partNumbers.length;pn++) { // For each part number...
fileName=partNumbers[pn].contents;
fileList=filePath.getFiles( RegExp(fileName + '(-\\d)?\.(tiff?|TIFF?|eps|EPS)')); // ...find graphic files with part number as name (could be with -digit at the end, like 25-101627-1)
prevParagraph=partNumbers[pn].parentStory.paragraphs.previousItem(partNumbers[pn].paragraphs[0]); // Take a paragraph preceding paragraph with part number
if (prevParagraph.characters[0].allGraphics.length && fileList.length) { // If fist character is an anchor for an image and new image was found...
linkedImage=prevParagraph.characters[0].allGraphics[0];
linkedImage.place (fileList[0]); // ...then place it!
}
}
Copy link to clipboard
Copied
Mitya,
Thank you for this script. I had to tweak it a little but I got it to work on a single page InDesign file as long as it was in the same folder as the image files. I'm wondering if it would be possible to create a script that follows this flowchart:
I have a spreadsheet with all the original part numbers and their corresponding new part numbers. This looking at a spreadsheet then looking into a specific folder for specific files must be complicated, but I thought I'd give it a shot.
Thanks again,
Lloyd
Copy link to clipboard
Copied
Hi Llyod,
Its possible to implement the flowchart that you have mentioned, it seems you have the main piece of the code working for you now, the only part is to read in the data from spreadsheet and wire it with the code that you have currently. Save the spreadsheet in the form of a csv which can be parsed by the JSX code and then the data from csv can be integrated with the code that you currently have.
Hope this helps
-Manan
Copy link to clipboard
Copied
Manan,
I appreciate your reply. The problem is that I don't know scripting. I might be able to get someone to look at the script Mitya provided and modify it, so I'll look around.
Thank you.
Copy link to clipboard
Copied
Hi Lloyd,
I was on the road, couldn't answer you earlier. It definetly not a big work to modify a script like you describe, so let's finish it) Could you send me a spreadsheet and your tweaked version of script - I'll try to return you final code tomorrow.
Copy link to clipboard
Copied
Mitya,
I apologize, I've been out of the office. I will send you some information in the form I'd like to use along with an explanation. Where should I send it?
Lloyd
Copy link to clipboard
Copied
Hi Mitya,
it's best practice to communicate mail addresses with private messages through the forum software.
When logged in just hover over the screen name of a participant and the button "Message" should pop up.
If you are posting your mail address here out in the open the spam bots will grap it easily…
Regards,
Uwe
Copy link to clipboard
Copied
Hey Lloyd
As Manan said, this is easily in the realms of scripting with InDesign, but if I'm honest, it is a bit more complex for someone new to scripting to start with!
There are plenty of people in this forum more than capable to create this as a complete script, so maybe worth seeing if anyone here would be willing to be contacted to create this for you.
It is something I would be capable to do, but there are others here far more experienced than I am!
Cheers
Roy