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

relink all selected

Community Expert ,
Sep 11, 2017 Sep 11, 2017

Copy link to clipboard

Copied

CarlosCanto​ wrote this script for me years ago, but seems to not work anymore on

Mac OS 10.10.5

CC2015.3

Is supposed to relink all instance of an image, as for example on a carton in packaging design we make have the same picture of an apple pie on all 6 sides. Is annoying to run the link panel 6 times rather than one command. This was further aggravated by the Mac OS not remember ing the last location, which default folder used to correct, but that seems to work now.

#target Illustrator

// script.name = relinkAllSelected.jsx;

// script.description = relinks all selected placed images at once;

// script.required = select at least one linked image before running;

// script.parent = CarlosCanto // 7/12/11;

// script.elegant = false;

var idoc = app.activeDocument;

sel = idoc.selection;

if (sel.length>0)

     {

       

          for (i=0 ; i<sel.length ; i++ )

               {

                   if (sel.typename == "PlacedItem")

                        {

    

                            var iplaced = sel;

       var file = File.openDialog ("open file " + iplaced.file );

                            iplaced.file = file;

                         }

               }

     }

else

     {

          alert("select at least one placed item before running");

     }

TOPICS
Scripting

Views

6.2K

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

correct answers 2 Correct answers

Community Expert , Sep 12, 2017 Sep 12, 2017

Oops

Moving a line before the variable was defined is never a good idea.

var file = File.openDialog ("open file " + iplaced.file );

should be

var file = File.openDialog ("open file ");

Votes

Translate

Translate
Community Expert , Nov 23, 2019 Nov 23, 2019

Hi dimitri, sorry but it works fine here, I'm on Windows though.

 

are you using this script?

 

 

//#target Illustrator
 
// script.name = relinkAllSelected.jsx;
// script.description = relinks all selected placed images at once;
// script.required = select at least one linked image before running;
// script.parent = CarlosCanto // 7/12/11; 05/12/19 updated for CC2019
// script.elegant = false;
 
var idoc = app.activeDocument;
sel = idoc.selection;
if (sel.length>0) {
      var file = File.openD
...

Votes

Translate

Translate
Adobe
Valorous Hero ,
Sep 11, 2017 Sep 11, 2017

Copy link to clipboard

Copied

Have you thought of using the Illustrator variable data to help with this workflow?

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 ,
Sep 11, 2017 Sep 11, 2017

Copy link to clipboard

Copied

Would that help here? All I want to do is update 6 links of:

\Volumes\Kaleidoscope Server\1 Jobs\ABCD\AWG\79786 AWG Best Choice Ice Cream Range Design\5 Implementation\1 Images\Vanilla1.psd

to

\Volumes\Kaleidoscope Server\1 Jobs\ABCD\AWG\79786 AWG Best Choice Ice Cream Range Design\5 Implementation\1 Images\Vanilla2.psd

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
Valorous Hero ,
Sep 12, 2017 Sep 12, 2017

Copy link to clipboard

Copied

In your case, probably not. Or, probably may, depending if you find yourself needing to replace multiple images with different images!

You see, in a less-than-ideal workaround, you can save a spreadsheet .txt or .csv file with just these contents:

@my-image
newImage.png

The document's images you want to relink would need to be named "my-image" so they can be bound by name via VariableImporter.jsx

The thing is, you will need to change "newImage.png" to your new image name every time - so you'd have to keep this text file open and make edits to it throughout the day. The downsides are the spreadsheet, the clicks to open it inside VariableImporter dialog, but the upside is that your csv can be a nice spot to keep your latest used file path (instead of getting it from links panel), your placed files are all replaced at the same time, and if needed, you can actually relink multiple sets of placed files, using multiple @my-image-x columns.

Another thing is, I need to fix up the VariableImporter to remember name of last csv location used, so that you don't have to navigate to it every time. And, I have a bug which messes up server paths on Windows. So, I'll get back to you with the changes

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 ,
Sep 12, 2017 Sep 12, 2017

Copy link to clipboard

Copied

Thanks Sily-V. Variable data is one of the very few things I have not used much in illustrator. I pick up files form designers, and do not get a lot of time to make them print ready photo retouch and lay out all the panels to the die line, so seeing the script as a quicker solution.

Carlos or someone else may be able to figure out the script, but have not seen him in awhile on the forums.

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 ,
Sep 12, 2017 Sep 12, 2017

Copy link to clipboard

Copied

MikeGondek​

Hope so CarlosCanto​ will be not angry about the changing.

Try this

#target Illustrator

// script.name = relinkAllSelected.jsx;

// script.description = relinks all selected placed images at once;

// script.required = select at least one linked image before running;

// script.parent = CarlosCanto // 7/12/11;

// script.elegant = false;

// https://forums.adobe.com/thread/2381744

// ---------------------------------------------------------------------------------

// changed: relink all selected placed items with ONE new file

// ---------------------------------------------------------------------------------

var idoc = app.activeDocument;

sel = idoc.selection;

if (sel.length>0)

    {

    var file = File.openDialog ("open file " + iplaced.file );

    for (i=0 ; i<sel.length ; i++ )

        {

            if (sel.typename == "PlacedItem")

                {

                    var iplaced = sel;

                    //var file = File.openDialog ("open file " + iplaced.file );

                    iplaced.file = file;

                }

            }

        }

    else

    {

    alert("select at least one placed item before running");

}

Select the placed images and run this snippet.

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 ,
Sep 12, 2017 Sep 12, 2017

Copy link to clipboard

Copied

Thank you so much. Got an error. I tried both .js & .jsx file extension.

Screen Shot 2017-09-12 at 4.19.57 PM.png

FYI: To me does not matter if I need to select all images, one, or none. Whatever is easiest and most reliable for future Illustrator updates. Would even be happy if I could do a do a find /change to the code. eg: "ButterfingerCrunch 01.psd" to "ButterfingerCrunch 02.psd".

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 ,
Sep 12, 2017 Sep 12, 2017

Copy link to clipboard

Copied

Oops

Moving a line before the variable was defined is never a good idea.

var file = File.openDialog ("open file " + iplaced.file );

should be

var file = File.openDialog ("open file ");

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 ,
Sep 12, 2017 Sep 12, 2017

Copy link to clipboard

Copied

That did it! Thank You!

Screen Shot 2017-09-12 at 5.45.34 PM.png

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
Engaged ,
Nov 14, 2019 Nov 14, 2019

Copy link to clipboard

Copied

Good evening -

 

I'm running under Illustrator CC 23.1.1

And when I launch the script, well AI asks me to open a file (the new one), I click on "open"…

But after that nothing happen.

 

Any idea why?

Thank you

 

 

 

- Dimitri

 

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 ,
Nov 14, 2019 Nov 14, 2019

Copy link to clipboard

Copied

did you select your images on the artboard first?

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
Engaged ,
Nov 15, 2019 Nov 15, 2019

Copy link to clipboard

Copied

Hey Carlos -

 

Yes, I do, otherwise I'd get the "alert" message…

Any idea?

 

 

- Dimitri

 

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 ,
Nov 15, 2019 Nov 15, 2019

Copy link to clipboard

Copied

your images are probably rasterItems (embedded) instead of placed, can you confirm?

if that's the case, there's another version of the script that deals with both types of images

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
Engaged ,
Nov 15, 2019 Nov 15, 2019

Copy link to clipboard

Copied

Hello Carlos -

 

I double checked and they are not.

So they are NOT embedded.

 

 

- Dimitri

 

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 ,
Nov 18, 2019 Nov 18, 2019

Copy link to clipboard

Copied

Hi dimitri, can you share a sample file to play with?

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
Engaged ,
Nov 22, 2019 Nov 22, 2019

Copy link to clipboard

Copied

Hello Carlos -

 

Please, find here a rogh AI file with a couple of pictures —>   https://file.io/IxePDv

I run under Mac OS X Mojave 10.14.6 + AI CC2019

 

Big thanks for your lihghts and time.

 

 

 

- Dimitri

 

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 ,
Nov 23, 2019 Nov 23, 2019

Copy link to clipboard

Copied

Hi dimitri, sorry but it works fine here, I'm on Windows though.

 

are you using this script?

 

 

//#target Illustrator
 
// script.name = relinkAllSelected.jsx;
// script.description = relinks all selected placed images at once;
// script.required = select at least one linked image before running;
// script.parent = CarlosCanto // 7/12/11; 05/12/19 updated for CC2019
// script.elegant = false;
 
var idoc = app.activeDocument;
sel = idoc.selection;
if (sel.length>0) {
      var file = File.openDialog ("open file");
      file = new File(file.fsName.replace("file://","")); // Mac OS Lion fix by John Hawkinson
      
      for (i=0 ; i<sel.length ; i++ ) {
           if (sel[i].typename == "PlacedItem") {
                var iplaced = sel[i];
                iplaced.file = file;
             }
           if (sel[i].typename == "RasterItem") {
                var iplaced = idoc.placedItems.add();
                iplaced.file = file;
                
                iplaced.move(sel[i], ElementPlacement.PLACEBEFORE);

                h = sel[i].height;
                w = sel[i].width;
                x2 = sel[i].left;
                y2 = sel[i].top;

                iplaced.position = [x2+w/2-iplaced.width/2, y2-h/2+iplaced.height/2];
                
                sel[i].remove();
             }
       }
}
else
     {
          alert("select at least one placed item before running");
     }

 

 

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
Engaged ,
Nov 24, 2019 Nov 24, 2019

Copy link to clipboard

Copied

Good morning Carlos -

 

Apparently not,

but this one his working like a charm.   ðŸ˜„

 

Thank you sooooo much.

 

 

- Dimitri

 

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 ,
Feb 20, 2020 Feb 20, 2020

Copy link to clipboard

Copied

Here is a slightly more simple version

 

 

#target Illustrator

// script.name = relinkAllSelected.jsx;

// script.description = relinks all selected placed images at once;

// script.required = select at least one linked image before running;

// script.parent = CarlosCanto // 7/12/11;

// script.elegant = false;

// https://forums.adobe.com/thread/2381744

// ---------------------------------------------------------------------------------

// changed: relink all selected placed items with ONE new file

// ---------------------------------------------------------------------------------

var idoc = app.activeDocument;

sel = idoc.selection;

if (sel.length>0)

{

var file = File.openDialog ("open file");

for (i=0 ; i<sel.length ; i++ )

{

if (sel[i].typename == "PlacedItem")

{

var iplaced = sel[i];

//var file = File.openDialog ("open file " + iplaced.file );

iplaced.file = file;

}

}

}

else

{

alert("select at least one placed item before running");

}

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 Beginner ,
Jul 28, 2020 Jul 28, 2020

Copy link to clipboard

Copied

Is there a version of this script that allows for "show import options"?  Would like to change the artboard within an ai file that's being linked to. 

 

Thanks

K

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 Beginner ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

For anyone who still wants to use this script, I have refined it a bit to be able to replace every selected image through a multi-selection of files (jpg/jpeg/png) and if there are more selected images than files, it will loop the last file through your entire selection (good when you want to replace multiple images with 1 file).

const idoc = app.activeDocument;
const sel = idoc.selection;
if (sel.length > 0) {
     sel.reverse();
     // Select files
     var files = null;
     if ($.os.search(/windows/i) != -1) {
          // Windows
          files = File.openDialog("please select files", "*.jpg;*.jpeg;*.png", true);
     } else {
          // MacOs
          files = File.openDialog("please select files", getFiles, true);
     }
     if (files) {
          // Loop through selection
          for (x = 0; x < sel.length; x++ ) {
               var i = x;
               // Replace all leftover images with last selected image
               if (x >= files.length) { i = files.length - 1; }
               if (sel[x].typename == "PlacedItem") {
                    sel[x].file = files[i];
               } else if (sel[x].typename == "RasterItem") {
                    var iplaced = idoc.placedItems.add();
                    iplaced.file = files[i];
                    iplaced.move(sel[x], ElementPlacement.PLACEBEFORE);
                    iplaced.left = sel[x].left;
                    iplaced.top = sel[x].top;
                    iplaced.height = sel[x].height;
                    iplaced.width = sel[x].width;
                    sel[x].remove();
               }
          }
     } else { alert("select at least one file"); }
} else { alert("select at least one placed item before running"); }

// Get jpg, jpeg and png from files (macOs)
function getFiles(f) {
     return f.name.match(/\.(jpg|jpeg|png)$/i) != null || f.constructor.name == "Folder";
}

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 ,
Sep 07, 2023 Sep 07, 2023

Copy link to clipboard

Copied

LATEST

a litlte bit change for replace pdf ai psd and tif linked files


#target Illustrator

const idoc = app.activeDocument;
const sel = idoc.selection;
if (sel.length > 0) {
     sel.reverse();
     // Select files
     var files = null;
     if ($.os.search(/windows/i) != -1) {
          // Windows
          files = File.openDialog("please select files", "*.ai;*.pdf;*.psd;*.tif*.jpg;*.jpeg;*.png", true);
     } else {
          // MacOs
          files = File.openDialog("please select files", getFiles, true);
     }
     if (files) {
          // Loop through selection
          for (x = 0; x < sel.length; x++) {
               var i = x;
               // Replace all leftover images with last selected image
               if (x >= files.length) { i = files.length - 1; }
               if (sel[x].typename == "PlacedItem") {
                    sel[x].file = files[i];
               } else if (sel[x].typename == "RasterItem") {
                    var iplaced = idoc.placedItems.add();
                    iplaced.file = files[i];
                    iplaced.move(sel[x], ElementPlacement.PLACEBEFORE);
                    iplaced.left = sel[x].left;
                    iplaced.top = sel[x].top;
                    iplaced.height = sel[x].height;
                    iplaced.width = sel[x].width;
                    sel[x].remove();
               }
          }
     } else { alert("select at least one file"); }
} else { alert("select at least one placed item before running"); }

// Get jpg, jpeg and png from files (macOs)
function getFiles(f) {
     return f.name.match(/\.(pdf|ai|psd|tif|jpg|jpeg|png)$/i) != null || f.constructor.name == "Folder";
}

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