2 Replies Latest reply on Jul 30, 2013 5:50 PM by Yuliaart

    Relink files in Indd CS5, js

    Yuliaart Level 1

      Hi,

       

      I need to relink files in InDesign to the Link subfolder and what I have is not working:

       

      myDoc = app.activeDocument;

      myDocPath = myDoc.filePath;

       

      var indesignPages = myDoc.pages.length;

      var p = 0;

       

      for (var p =0; indesignPages > p; myDoc.pages[p++]){
      for (var a =0; a<myDoc.rectangles.length-1; a++){
      
      try{
      var myArt = myDoc.pages[p].rectangles[a].graphics[0];
          if (myArt.isValid ==true){
              var myArtName = myArt.itemLink.name;
              var myArtLocation = myDocPath + "/Links/" + myArtName;
              alert (myArtLocation)
          if (myArt.itemLink.status == LinkStatus.LINK_MISSING){
              myArt.itemLink.relink (myArtLocation);
          }
          if (myArt.itemLink.status == LinkStatus.LINK_OUT_OF_DATE){
          myArt.itemLink.update (myArtName);
          }
          }
      }catch (e){}
      }
      }
      

       

      And I am not sure why.

       

      It's running to the end and not giving me any errors, but the links remain unlinked.

      The location alert shows correct location.

       

      Thank you for your help.

      Yulia

        • 1. Re: Relink files in Indd CS5, js
          Jump_Over Level 5

          Hi,

           

          try this:

          var myDoc = app.activeDocument,
          myDocPath = myDoc.filePath,
          myLinks = myDoc.links.everyItem().getElements(),
          p, a = [], myArt, myArtName, myArtLocation;
          
          for ( p = 0; p < myLinks.length ; p++) {
               myArt = myLinks[p];
               myArtName = myArt.name;
               myArtLocation = File(myDocPath + "/Links/" + myArtName);
               if (!myArtLocation.exists) {
                    a.push(myArtName); 
                    continue;
                    }
               switch (myArt.status) {
                    case LinkStatus.LINK_MISSING:
                         myArt.relink (myArtLocation); break;
                    case LinkStatus.LINK_OUT_OF_DATE:
                         myArt.update(); break;
                    case LinkStatus.NORMAL: break;
                    default: alert ("Can't relink " + myArtName); break;
                    }
               }
          if (a.length > 0) a = "Files not found in 'Links' folder:\r" + a.join("\r");
          else a = "OK. Done!";
          alert (a);
          

           

          Jarek

          • 2. Re: Relink files in Indd CS5, js
            Yuliaart Level 1

            WOW! Thank you.

             

            It's great.

            Yulia