Skip to main content
Inspiring
August 24, 2020
Answered

Relinking multiple instances of the same file Broken?

  • August 24, 2020
  • 4 replies
  • 681 views

Hey smart people. Is this a bug or am I doing something wrong?

 

When I try to relink multiple instances of the same (missing) file to my illustrator document, it used to be that I could select in the links palette all the links to the same file and then illustrator would bring up the link dialog box for every instance that I had selected. Although it wasn't automated, I only had to double click on the name of the file to link to, and it would cycle to the next one.

 

Today I noticed that when I select mulitple links it only relinks one of them and I have to select each link separately. Am I missing something? Have they changed the way it works? 

 

Please advise, thanks. 

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer dDembicki

Holy Moly. It worked as expected this time. Is there a limit to the number of files or something maybe?

 

4 replies

marcg68495176
Inspiring
June 18, 2024

This script will replace all links of the same name with a new one of your choosing. 

/**
 * This script replaces all linked files with the same name at one time in Adobe Illustrator.
 * It allows the user to select the link to replace from a list of current links using a drop-down menu
 * and then choose the new file from a dialog.
 */

function replaceAllLinksWithSameName() {
    var doc = app.activeDocument;
    var placedItems = doc.placedItems;
    var linkNames = [];

    // Collect all unique link names
    for (var i = 0; i < placedItems.length; i++) {
        var placedItem = placedItems[i];
        if (placedItem.file) {
            var fileName = placedItem.file.name;

            // Check if the fileName is already in linkNames
            var isUnique = true;
            for (var j = 0; j < linkNames.length; j++) {
                if (linkNames[j] === fileName) {
                    isUnique = false;
                    break;
                }
            }

            if (isUnique) {
                linkNames.push(fileName);
            }
        }
    }

    if (linkNames.length === 0) {
        alert("No linked files found in the document.");
        return;
    }

    // Create a dialog for link selection
    var dialog = new Window("dialog", "Select Link to Replace");
    dialog.orientation = "column";

    var dropdown = dialog.add("dropdownlist", undefined, linkNames);
    dropdown.selection = 0;

    var okButton = dialog.add("button", undefined, "OK");
    okButton.onClick = function() {
        dialog.close(1);
    };

    if (dialog.show() != 1) {
        return;
    }

    var oldFileName = dropdown.selection.text;
    var newFile = File.openDialog("Select the new file to replace " + oldFileName);

    if (newFile) {
        var count = 0;

        for (var k = 0; k < placedItems.length; k++) {
            var placedItem = placedItems[k];
            if (placedItem.file && placedItem.file.name === oldFileName) {
                placedItem.file = newFile;
                count++;
            }
        }

        alert(count + " links have been replaced.");
    } else {
        alert("Operation cancelled or no file selected.");
    }
}

replaceAllLinksWithSameName();
dDembickiAuthor
Inspiring
August 8, 2024

A very late thank you for the script. I don't know how to use scripts, so it will take a minute for me to get up to speed. 

Ton Frederiks
Community Expert
Community Expert
August 8, 2024

Unfortunately I cannot get this script to work, but the script from Carlos Canto, that can be found here works for me:

https://community.adobe.com/t5/illustrator-discussions/relink-all-selected/m-p/10758819#M155685

 

Copy the script and paste it into a plain text document (not word or rich text, simple unformatted text).

Save it to the desktop as relinkAllSelected.jsx

Save Copy the script to the Illustrator application folder > Presets > Your Language folder > Scripts (you may need an admin password) and restart.

You can use the script by selecting all the links in your Illustrator file and select File > Scripts > relinkAllSelected from File > Scripts

Alternatively you can select the script from wherever you saved it using File > Scripts > Other Script.

dDembickiAuthorCorrect answer
Inspiring
August 24, 2020

Holy Moly. It worked as expected this time. Is there a limit to the number of files or something maybe?