4 Replies Latest reply on Aug 9, 2016 8:28 AM by Vamitul

    Error in script to relink in Indesing

    Dinafanoe

      Yesterday  I was given a script that relinked in Indesign so fast - and I have used  numerous times yesterday and today.

       

      BUT al of a sudden it gives me a java script error, no 29942 (se attached screenshot)Screen Shot 2016-08-05 at 14.28.09.png

       

      the script is:

       

      function main() {

          var doc = app.activeDocument;

          var myLinks = doc.links.everyItem().getElements();

          var linkObj = {};

          // create inital object

          /* linkObject {

                          [path]{missingNr,

                                arrayOfMissingLinks}

                                } */

       

       

       

       

          for (var i = 0; i < myLinks.length; i++) {

              if (myLinks[i].status == LinkStatus.LINK_MISSING) {

                  var myPath = File(myLinks[i].filePath).path.toString();

                  if (linkObj[myPath] == undefined) {

                      linkObj[myPath] = {

                          missingNr: 1,

                          missingLinks: [myLinks[i]],

                          newPath: ''

                      }

       

       

       

       

                  } else {

                      linkObj[myPath].missingNr++;

                      linkObj[myPath].missingLinks.push(myLinks[i].getElements()[0]);

                  }

              }

          }

          //$.writeln(linkObj.toSource());

          var myDialog = new Window('dialog', 'Link Chaser:', undefined);

          var panel1 = myDialog.add('panel', undefined, 'Double click to select new path');

          panel1.align = ['fill', 'fill'];

          var myList = panel1.add('listBox', undefined, "", {

              columnWidths: [160, 160, 130],

              numberOfColumns: 3,

              showHeaders: true,

              columnTitles: ['Old Path', 'New Path', 'Nr. of missing links']

          });

          myList.size = [450, 200];

          myList.align = ['fill', 'fill'];

       

       

       

       

          for (var missingPath in linkObj) {

              with(myList.add('item', missingPath)) {

                  subItems[0].text = linkObj[missingPath].newPath;

                  subItems[1].text = linkObj[missingPath].missingNr;

              }

          }

          myList.onDoubleClick = function() {

              var myNewPath = (new Folder(app.activeDocument.filePath).selectDlg("Select New Folder") || '').toString();

              myList.selection.subItems[0].text = myNewPath;

              linkObj[myList.selection.text].newPath = myNewPath;

          }

          myDialog.add('button', undefined, "Ok", {

              name: "ok"

          });

          myDialog.add('button', undefined, "Cancel", {

              name: "cancel"

          });

          if (myDialog.show() == 1) {

              for (var i in linkObj) {

                  if (linkObj[i].newPath != '') {

                      var fixedNr = 0;

                      var links = linkObj[i].missingLinks

                      for (var j = 0; j < links.length; j++) {

                          var newFile = File(linkObj[i].newPath + "/" + links[j].name);

                          if (newFile.exists) {

                              fixedNr++;

                              links[j].relink(newFile);

                          }

       

       

       

       

                      }

                      alert('In folder:\n' + linkObj[i].newPath + '\n' +

                          'Fixed ' + fixedNr + ' links out of ' + linkObj[i].missingNr + '\n' +

                          'Please check');

                  }

              }

          };

      }

      app.doScript('main()', undefined, undefined, UndoModes.entireScript, "Link Chaser");

       

       

      I have NOT changed anything, any procedure and the document is similar to the other ones so I dont understand why this is failing :-(

       

      Any help please...???