3 Replies Latest reply on Jul 25, 2016 1:46 PM by Vova_p

    CS6 placedItems relink method, sometimes producing Error: 376('x ')




      I am creating a script on illustrator CS6 that will loop through all the images and relink these images to there current location, it is used to update all of the links in the file. However sometimes when i run this script i will get the error 376('x ') i have searched for the meaning of this and cannot find it anywhere. It is being written in extendscript, the code i am using is shown below:


      // execute the main function



      // Construct the main function

      function main() {


              var retVal = "OK";


              // Check the app is CS6 or above

              if ( parseFloat ( app.version ) < 16 ) {


                      alert("You must run this script in CS6 or above.");

                      return "Script must be run in CS6 or above.";



              //check for open document

              if (app.documents.length == 0) {




                        //show error when nothing is open.

                      alert("Please have at least one document open");

                      retVal = "Error";



              //check for images within document 

              if (app.activeDocument.placedItems.length == 0) {


                      //show error when there is no images

                       alert("No images in document");

                       retVal = "Error";



              else {


                      //active document variable

                      var ActiveFile = app.activeDocument;


                      // Declare array for the documents original layer states.

                      var originalLockedLayerStates = [];


                      // Declare array for the documents original layer states.

                      var originalVisibleLayerStates = [];



                      // Loop through the docs layers and capture the locked states of each one.

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


                              // Capture statues here

                              originalLockedLayerStates.push ( ActiveFile.layers[j].locked);

                              originalVisibleLayerStates.push ( ActiveFile.layers[j].visible);


                              // Unlock/Unhide layers here

                              ActiveFile.layers[j].locked = false;

                              ActiveFile.layers[j].visible = true;




                      // Create array variable for all placed images

                      var placedFiles = [];




                      // for every image in the active doc....

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


                              // try and...

                              try {

                                      // add the full image path to the array



                                      // then update the link in the active doc.

                                      ActiveFile.placedItems[i].relink (ActiveFile.placedItems[i].file);



                              // If the relink fails catch it here

                              catch (e) {

                                      // push the object name of the link that wouldn't update into this array.

                                      retVal = "Error";




                      // If this array is empty, then nothing went wrong and....

                      if ( retVal == "Error" ) {


                              // alert the user showing them the name of the problem link.

                              alert("Some image(s) could not be updated");




                      // otherwise there were issues and...

                      else if ( retVal == "OK" ){


                              // alert a success message

                              alert("Successfully updated " + placedFiles.length + " link(s)");       




              // Once the links have been updated, set the layers states back to how they were

              for ( var k = 0 ; k < ActiveFile.layers.length; k++ ) {


                      // Put layer back to it's original state.

                      ActiveFile.layers[k].locked = originalLockedLayerStates[k];

                      ActiveFile.layers[k].visible = originalVisibleLayerStates[k];




              // Once all the links have been updated, refresh the page.





          return retVal;



      if anyone has any suggestions as to why this may be happening i would be very greatfull.