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

Indd - JS: Searching an image in subfolders and relinking

New Here ,
Jul 09, 2008 Jul 09, 2008

Copy link to clipboard

Copied

Hi,

Can any one help me....
In an Indesign Document I want to relink all the images to a new path.
Please see the below script, it search for the images in a specified path only. But i want to search the images in a particular directory along with its sub-folder too.

var myFolder = Folder.selectDialog("Select Folder for Images");
var new_path = myFolder+ '/'
imgs = app.activeDocument.allGraphics
for (i = 0; i < imgs.length; i++)
{

img = imgs.itemLink

myFile = File (new_path + img.name);

if (myFile.exists) {
img.relink (File (new_path + img.name))
img.update()
}
}

Thanks in advance,
Bharathi Raja G.
TOPICS
Scripting

Views

1.8K

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
Contributor ,
Jul 09, 2008 Jul 09, 2008

Copy link to clipboard

Copied

Hi,

I am just working on a script like yours.
To catch files in subfolders I use the following function:


var topFolder = Folder.selectDialog();
var myResult = scanSubFolders( topFolder );

function scanSubFolders( tFolder )
{
var sFolders = new Array();
var allFiles = new Array();
sFolders[0] = tFolder;
for ( var j = 0; j < sFolders.length; j++ ) // loop through folders
{
var procFiles = sFolders.getFiles();
for ( var k = 0; k < procFiles.length; k++ ) // loop through this folder contents
{
if ( procFiles instanceof File )
allFiles.push( procFiles );
else if ( procFiles instanceof Folder )
sFolders.push( procFiles );
}
}
return allFiles;
}


If you wish to you can return the subfolders too:

return {files:allFiles, folders:sFolders};


Martin

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
Explorer ,
Jul 10, 2008 Jul 10, 2008

Copy link to clipboard

Copied

Here's what I use to locate files in a tree:

function findFiles(folder, mask) {
var files = folder.getFiles(mask);
var folders = folder.getFiles(function(f) { return f instanceof Folder; });

for (var i = 0; i < folders.length; i++) {
var f = folders;
var ffs = findFiles(f, mask);

// Array.concat occasionally fails in CS/CS2. Do it manually
while (ffs.length > 0) {
files.push(ffs.shift());
}
}
return files;
};

This has been sliced out of some other code

The mask parameter can be a string, RegExp, or a function. In your case, the
call would probably look something like this:

myFile = findFile(img.name);

-X
--
for photoshop scripting solutions of all sorts
contact: xbytor@gmail.com

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
Contributor ,
Jul 09, 2008 Jul 09, 2008

Copy link to clipboard

Copied

Hello Bharathi,

you will have to take care of one thing:
> img = imgs.itemLink

There may be images without a link (e.g. embedded images).
With them you would run into an error adressing their itemLink.

Martin

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
Guru ,
Jul 10, 2008 Jul 10, 2008

Copy link to clipboard

Copied

Hi Bharathi,

I recently wrote a similar script, you can download it from here:
http://www.businessweekly.h.com.ua/relink.html

See discussion here:
http://www.adobeforums.com/webx?128@@.59b50466

Kasyan

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
New Here ,
Jul 10, 2008 Jul 10, 2008

Copy link to clipboard

Copied

Hi,

Thanks for your immediate response and timely help.
I will check with it.

Bharathi Raja G.

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
New Here ,
Jul 14, 2008 Jul 14, 2008

Copy link to clipboard

Copied

Hi Kasyan,

The script in below links is not working for MAC. But in PC it works well. Can you please check with it

http://www.businessweekly.h.com.ua/relink.html

Thanks
Bharathi Raja G.

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
People's Champ ,
Jul 14, 2008 Jul 14, 2008

Copy link to clipboard

Copied

Something that work on PC should work on mac & the only reason it fails may have only one reason : It is the way to talk to folders.
on PC file paths will be like "c:/xxx/yyyy/zzz" or "/c/xxx/yyy/zzz" when it's more like ":Macintosh HD:Users:John Doe:xxx:yyy:zzz"

So I will check for file and folder paths as a priority degug way.
Loic

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
Participant ,
Jul 14, 2008 Jul 14, 2008

Copy link to clipboard

Copied

The filePath property takes two forms. When it is the property of a link, it is a platform-dependent string. The way to work with this property in a cross-platform or platform-independent way is to always do this:

myLinkedFilePath = File(myLink.filePath).fullName;

that will give you exactly what myLink.filePath purports to give you but in a platform independent format that works on either platform even if the link in question started life on the other platform.

Dave

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
New Here ,
Jul 22, 2008 Jul 22, 2008

Copy link to clipboard

Copied

Kasyan -- your script works great. Thank you!!

-- Rick

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
Guru ,
Aug 06, 2008 Aug 06, 2008

Copy link to clipboard

Copied

Hi Bharathi Raja G,

I just returned from vacation so I couldnt respond you earlier, but I hope you are still reading this forum.

> The script in below links is not working for MAC.

Actually, I wrote it for both platforms and I tested it, although superficially, on Mac and PC.

> Can you please check with it

Yes, but I need more information: what error message you get, the line number the script stops.

Kasyan

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
New Here ,
Aug 09, 2008 Aug 09, 2008

Copy link to clipboard

Copied

Hi Kasyan,

Sorry for the Late reply.
When I run the script on mac I got error with the progress bar.

Especially I am getting error with the below coding

------------------------------------------------------------
var w = new Window ( 'window', myCurrFolderName );
var pb = w.add ('progressbar', [12, 12, 350, 24], 0, stop);
var txt = w.add('statictext');
txt.bounds = [0, 0, 340, 20];
txt.alignment = "left";
w.show();
var a = 1;
------------------------------------------------------------
But, the scripts runs well by removing the progress bar coding.

Also, Can you keep a checkpoint(to exit the process) that if all the images was linked successfully the script should stop searching for the further folders.
For Example: If I search an Image in a directory contains 10 sub folders in which the required image is in 1st sub folder. The script
should not search for the remaining 2-10 sub folders.

Thanks for your response,
Bharathi Raja G.

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
Guru ,
Aug 10, 2008 Aug 10, 2008

Copy link to clipboard

Copied

>When I run the script on mac I got error with the progress bar.

It looks like you have CS2. Recently I received an e-mail from a guy who had a similar problem so I posted two versions of the script, both for CS2 and CS3.

>Can you keep a checkpoint(to exit the process) that if all the images was linked successfully the script should stop searching for the further folders.

I'll work on it when I have time.

Kasyan

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
New Here ,
Aug 25, 2008 Aug 25, 2008

Copy link to clipboard

Copied

Hi Kasyan

Good Day. I have received Indesign files from Copenhagen. I dont know why the all the links are missing.

The links looks like this:

Dell:ImageBank:Products_Frontcover:None_environment_front:Printers_nev_fc:1720_laser_prn_nev:layouts:1720_prn_nev_02b_fc.psd

All the link files are in our server.

ImageBank\Products_Frontcover\None_environment_front\Printers_nev_fc\1720_laser_prn_nev:layouts\1720_prn_nev_02b_fc.psd

The problem is the file location shows : instant of \

Can you please help me out we are using Indesign CS.

Thanks

Shanto

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
Guru ,
Aug 26, 2008 Aug 26, 2008

Copy link to clipboard

Copied

LATEST
Hi Shanto,

You can download a script for updating path names in links: http://www.businessweekly.h.com.ua/relink.html
You select a folder, and, for every image in the active document, it searches for the file that has the same name as the old one, and if it's found, relinks it.
If the file with the exact name is not found, the script tries to find a file with the same base name but a different extension (".psd", ".tif", ".jpg", ".ai", ".eps", ".pdf", ".indd").
If the script doesn't find the new file in the chosen folder, it repeats the above-mentioned process for every subfolder.
But this script was written for CS2/CS3 and I have doubt that it would work in CS. I can’t check this as I don’t have CS any more.

To all appearance, Indesign files, you received, were created on Mac, but you are on PC. I remember this problem in CS – it has been corrected since CS2.
In such cases I use the following workaround:
1.Copy Indesign file to the folder where links located.
2.Open it, Indesign should find all lost links in this folder and its subfolders.
3.Save and close the document.
4.Copy/move the Indesign file to its original location.

Kasyan

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