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

relinking broken links with JSX

Explorer ,
Aug 07, 2013 Aug 07, 2013

Copy link to clipboard

Copied

Okay,

Say I have a series of folders and I have linked art and the files they are linked to all mixed up in these folders. My file structure is as such;

myFiles\HH01000-01999\HH01000-HH01099\HH001001.PDF

and now I need to change the file structure to this;

myFiles\HH\HH01000-01999\HH01000-HH01099\HH001001.PDF

adding the folder HH breaks the links.

What is the best way to identify the broken link and change its path with JSX? Anybody got any ideas?

TOPICS
Scripting

Views

1.4K

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
Adobe
Explorer ,
Aug 07, 2013 Aug 07, 2013

Copy link to clipboard

Copied

This little test I did allows me to retrieve the path of each linked image.

myVar = app.activeDocument.placedItems;

for(i=0; i < myVar.length; i++) {

fileName = myVar.file.path.toString();

alert(fileName);  

}

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 ,
Aug 07, 2013 Aug 07, 2013

Copy link to clipboard

Copied

Does anyone know if it is possible to change the path of a linked item with a script? That seems to be my biggest problem.

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 08, 2013 Aug 08, 2013

Copy link to clipboard

Copied

Passing a new file is simple enough… somePlaceItem.file = File( someNewPath );

The issue you will have is if you have already moved the links to new location then you can't access the missing file object…

You would need to read the link info from the XMP metadata instead.

If you have not yet moved the files then you may be able the have script get, move, relink on the fly…

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 ,
Aug 10, 2013 Aug 10, 2013

Copy link to clipboard

Copied

Thanks for the info Mark.

I have looked into it and broken links will not be a problem. We are copying the folder structure and changing the folder structure on the copy. All linked art will still point to the original source that has not been changed.

so as my script goes through and changes the links it will not have a problem.

Now I have to figure out how to evaluate the path to check for HH folder and if does not find it then change the path.

illustrations/001000-001999/001000-001099/HH001032.pdf

this path it would not find the HH folder in the path and it would need to change it to

illustrations/HH/001000-001999/001000-001099/HH001032.pdf

I'm still working on that.

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
Community Expert ,
Aug 10, 2013 Aug 10, 2013

Copy link to clipboard

Copied

use the file name string to search for "FolderA" and replace it with "FolderB", then build a new file with the new string

var file = File("illustrations/001000-001999/001000-001099/HH001032.pdf");

var oldFolder = "illustrations";

var newFolder = "illustrations/HH";

file = new File(file.fsName.replace(oldFolder, newFolder));

alert(file.exists);

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 ,
Aug 11, 2013 Aug 11, 2013

Copy link to clipboard

Copied

Thanks Carlos,

this is how i ended up getting it done.

function changeLinkedArt () {

    linkedPath = app.activeDocument.placedItems;

    outcome = 0;

for(i=0; i < linkedPath.length; i++) {

    linkedPathArray = linkedPath.file.path.split("/");

    for(j=0; j < linkedPathArray.length; j++) {

        if(linkedPathArray === "HH") {

            outcome = 1;

            }

        }

    if (outcome === 0) {

        fileName = linkedPath.file.toString();

        linkedFileArray = fileName.split("/");

        for(k=0; k < linkedFileArray.length; k++) {

            if(linkedFileArray === "illustrations") {

                linkedFileArray = linkedFileArray + "/HH";

                NewIndexLine = linkedFileArray.join("/");

                //alert(NewIndexLine);

                linkedPath.file=File(NewIndexLine);

            }

        }

    }

    outcome = 0;

}          

}  

modified an adobe script to open all files in a folder and run the script on all of them.

wanted to build some arrays to change all files in multiple folders but i could not get the ".getFiles( fileType );" to take a path instead of the Folder.selectDialog.

thats the only thing that bugs me.

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 12, 2013 Aug 12, 2013

Copy link to clipboard

Copied

LATEST

Folder.getFiles( /\.(ai|pfd)$/i );

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