6 Replies Latest reply on Oct 23, 2009 8:15 PM by Yuliaart

    Link update in InDesign CS4 JS

    Yuliaart Level 1

      Hi, I need some help. This loop use to work, but know it's giving me an error, and when I added the alert I see that it's giving me only first letter of the file's name. Could you help me to find out what happened.

       


      for (var a =0; a<app.activeDocument.rectangles.length-1; a++){

       

      myArt = app.activeDocument.rectangles[a].graphics[0];
      myArtName = myArt.itemLink.name[0];
      alert (myArtName);
      myArt.itemLink.update (myArtName);
      }

       

       

      Thank you very much.

      Yulia

        • 1. Re: Link update in InDesign CS4 JS
          ramkumar.vp Level 3

          Hi Yulia,


          Wrong: myArtName = myArt.itemLink.name[0];


          Correct : myArtName = myArt.itemLink.name;


          itemLink.name is a string, if you get the String[0] it returns the first character.


          I think now you got it.


          Regards,

          Ramkumar

          • 2. Re: Link update in InDesign CS4 JS
            Yuliaart Level 1

            Thank you, Ramkumar.

             

            That helped. Now I am stuck on the next thing. It updates the broken link, but gives me an error when link is good. So I am trying to figure out an IF statement, so it only updates broken links. Here what I've tried and none of it works:


            for (var a =0; a<app.activeDocument.rectangles.length-1; a++){

             

            myArt = app.activeDocument.rectangles[a].graphics[0];
            myArtName = myArt.itemLink.name;
            var myLink = myArt.itemLink;

                if (myLink.edited = true)

                myArt.itemLink.update (myArtName)
            }

             

             

            or


            for (var a =0; a<app.activeDocument.rectangles.length-1; a++){

             

            myArt = app.activeDocument.rectangles[a].graphics[0];
            myArtName = myArt.itemLink.name;

            if (myArt.itemLink.edited = true)
                myArt.itemLink.update (myArtName);
            }

             

            or

             

             

            for (var a =0; a<app.activeDocument.rectangles.length-1; a++){


            myArt = app.activeDocument.rectangles[a].graphics[0];
            myArtName = myArt.itemLink.name;

            if (myArt.itemLink.linkStatus = LINK_OUT_OF_DATE)
                 myArt.itemLink.update (myArtName);
            }

             

             

            Thank you so much for your help.

            Yulia

            • 3. Re: Link update in InDesign CS4 JS
              [Jongware] Most Valuable Participant

              (w/o actually trying!) -- the last variant might work if you change it to

               

              if (myArt.itemLink.linkStatus == LinkStatus.LINK_OUT_OF_DATE)

               

              1st: To assign, use single equate; to compare use double equates

              2nd: Use full names for enumerations -- including its type.

               

              And I now see another tiny but potentially irritating bug

               

              for (var a =0; a<app.activeDocument.rectangles.length-1; a++)

               

              will process all but the very last rectangle. Don't use '-1' in combination with '<' (think about what this does).

              • 4. Re: Link update in InDesign CS4 JS
                Yuliaart Level 1

                Thank you, guys. It works perfectly now:

                 

                 

                 

                function checkLinks (){
                    for (var a =0; a<app.activeDocument.rectangles.length-1; a++){

                 

                var myArt = app.activeDocument.rectangles[a].graphics[0];
                    if (myArt.isValid ==true)
                    {
                        var myArtName = myArt.itemLink.name;
                    //alert (myArtName);
                    if (myArt.itemLink.status == LinkStatus.LINK_MISSING)
                    {
                        alert ("Artwork's link is missing. Please re-link the artwork");
                    exit ();
                    }
                    if (myArt.itemLink.status == LinkStatus.LINK_OUT_OF_DATE)
                    myArt.itemLink.update (myArtName);
                    }
                }
                }

                 

                 

                Highly appreciate your help.

                Yulia

                • 5. Re: Link update in InDesign CS4 JS
                  [Jongware] Most Valuable Participant

                  Perfectly, not quite yet -- but you are getting there!

                   

                  (What happens when the last image is no good? Hint: see my previous post ...)

                  • 6. Re: Link update in InDesign CS4 JS
                    Yuliaart Level 1

                    Hi, Theun, that's how we originally tried it and it didn't work, so we had to deduct 1 from the lenth and now it works. It doesn't make sense, but it does check the last artwork.


                    I do appreciate your attention to detail and catching additional errors, because it does help.

                     

                    Yulia