Skip to main content
Participating Frequently
March 21, 2014
Question

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

  • March 21, 2014
  • 2 replies
  • 1539 views

Hi,

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

main();

// 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.locked);

                        originalVisibleLayerStates.push ( ActiveFile.layers.visible);

                       

                        // Unlock/Unhide layers here

                        ActiveFile.layers.locked = false;

                        ActiveFile.layers.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

                                placedFiles.push(ActiveFile.placedItems.file.fullName);

                                // then update the link in the active doc.

                                ActiveFile.placedItems.relink (ActiveFile.placedItems.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.locked = originalLockedLayerStates;

                ActiveFile.layers.visible = originalVisibleLayerStates;

        }

       

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

        app.redraw()

       

        }

   

    return retVal;

}

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

Thanks,

Tom

This topic has been closed for replies.

2 replies

Vova_p
Participant
July 25, 2016

i hope it's will help you.

So, the error apeared on this stroke

ActiveFile.placedItems.relink (ActiveFile.placedItems.file);

And i had the same error, because this syntax is invalid.

This examlpe will be work:

file = new File("D:/1.jpg");

app.activeDocument.placedItems[0].file = file;

it is a right command to relink image.

Inspiring
March 23, 2014

Not sure what is the real purpose of your script, but why you dont want to use Emded() method?

t1d2c3Author
Participating Frequently
March 24, 2014

The purpose is to relink the placed images in the document to there current file paths, and im not too sure what the embed method does, but i do not want to embed the images, just update the links for the images