Skip to main content
Participating Frequently
March 13, 2019
Answered

[ Branched ] How to relink all embedded images under clipping mask

  • March 13, 2019
  • 2 replies
  • 1625 views

Hey pixxxel schubser It works for link image.
But i have many files with embedded image under clipping mask. Could you help make a change the script for it? Thanks

[ Branched by moderator from previous discussion ] --> relink all selected

This topic has been closed for replies.
Correct answer CarlosCanto

here you go, you still need to select the clipped images (the images themselves, not the mask). You can do that with the group selection tool

 

//#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");
     }

2 replies

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
May 12, 2019

here you go, you still need to select the clipped images (the images themselves, not the mask). You can do that with the group selection tool

 

//#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");
     }
RobertNgAuthor
Participating Frequently
May 13, 2019

It's works. Thank you so much!

Known Participant
May 11, 2019

This is what I would need as well