• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Script that worked now giving a 1302 error

Community Beginner ,
Oct 05, 2012 Oct 05, 2012

Copy link to clipboard

Copied

I am getting an error with a script i have used before without any problems.

The script updates the only image at the bottom of a single page PDF and saves the changed PDF in another folder.

It asks me to locate the folder of PDFs to be modified.
It asks me to locate the folder where the modified PDFs will be saved.
It asks me to select the new image that will be used.
It will then update the image and resizes it and save the PDF in the specified folder.

I don't get this error on all PDFs but i get it at least once every 10 PDFs  (and there are over a 1,000 PDFs).


The error i get is this:

Error 1302:No such element
Line:27
->      rip=
doc.rasterItems[0].position;

I get this error regardless of whether the script is run in CS3 or CS5.


Additional info.
I ran this script in CS3 and it worked. At a later date i ran another script on the folder of modified PDFs in CS5 that deleted any

unnessesary elements outside the artboard, it selected All on the Artboard - then inversed the selection - and deleted any selected items

followed by save and close.
I have tried making sure the "new" image has the same name as the image being replaced but this made no difference.

I am using Illustrator on Vista.

The script is below:

#target illustrator

function replaceImage() {

 

          var i, doc, fileList, inFolder, outFolder, opts, pic, rep, rip, saveFile, uIL;

          inFolder = Folder.selectDialog( 'Please choose your Folder of AI PDFs…' );

 

          outFolder = Folder.selectDialog( 'Please choose a Folder to save AI PDFs in…' );

 

          pic = File.openDialog( 'Please choose your replacement Image…' );

          if ( inFolder != null && outFolder  != null && pic != null ) {

                    fileList = inFolder.getFiles( /\.pdf$/i );

                    if ( fileList.length > 0 ) {

 

                              uIL = app.userInteractionLevel;

 

                              app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

 

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

 

                                        doc = app.open( fileList );

 

                                        rip = doc.rasterItems[0].position;

 

                                        rep = doc.placedItems.add();

 

                                        rep.file = pic;

 

                                        rep.move( doc.rasterItems[0], ElementPlacement.PLACEBEFORE )

 

                                        rep.position = rip;

 

                                        rep.resize( 31.414, 31.414, true, true, true, true, 100, Transformation.TOPLEFT );

 

                                        doc.rasterItems[0].remove();

 

                                        rep.embed();

 

                                        opts = new PDFSaveOptions();

 

                                        opts.pDFPreset = '[Illustrator Default]';

 

                                        saveFile = File( outFolder + '/' + doc.name );

 

                                        doc.saveAs( saveFile, opts );

 

                                        doc.close( SaveOptions.DONOTSAVECHANGES );

 

                              };

 

                              app.userInteractionLevel = uIL;

 

                    } else {

 

                              alert( 'This Folder contained NO Illustrator PDF files?' );

 

                    };

          };

};

 

replaceImage();

TOPICS
Scripting

Views

5.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 05, 2012 Oct 05, 2012

try this one

#target illustrator

function replaceImage() {

          var i, doc, fileList, inFolder, outFolder, opts, pic, rep, rip, saveFile, uIL;

          inFolder = Folder.selectDialog( 'Please choose your Folder of AI PDFs…' );

          outFolder = Folder.selectDialog( 'Please choose a Folder to save AI PDFs in…' );

          pic = File.openDialog( 'Please choose your replacement Image…' );

          if ( inFolder != null && outFolder  != null && pic != null ) {

                    fileList = inFo

...

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 05, 2012 Oct 05, 2012

Copy link to clipboard

Copied

the error means that there are no "raster" elements in one of the files, or in illustrator talk, no "embeded" images. Could it be that the image is "linked"?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 05, 2012 Oct 05, 2012

Copy link to clipboard

Copied

Yes it is a linked image.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 05, 2012 Oct 05, 2012

Copy link to clipboard

Copied

try this one

#target illustrator

function replaceImage() {

          var i, doc, fileList, inFolder, outFolder, opts, pic, rep, rip, saveFile, uIL;

          inFolder = Folder.selectDialog( 'Please choose your Folder of AI PDFs…' );

          outFolder = Folder.selectDialog( 'Please choose a Folder to save AI PDFs in…' );

          pic = File.openDialog( 'Please choose your replacement Image…' );

          if ( inFolder != null && outFolder  != null && pic != null ) {

                    fileList = inFolder.getFiles( /\.pdf$/i );

                    if ( fileList.length > 0 ) {

                              uIL = app.userInteractionLevel;

                              app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

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

                                        doc = app.open( fileList );

                                       // rip = doc.rasterItems[0].position;

                                        try {

                                            var ripObj = doc.rasterItems[0];

                                        }

                                        catch (e) {

                                            var ripObj = doc.placedItems[0];

                                        }

                                        rip = ripObj.position;

                                        rep = doc.placedItems.add();

                                        rep.file = pic;

                                        //rep.move( doc.rasterItems[0], ElementPlacement.PLACEBEFORE );

                                        rep.move( ripObj, ElementPlacement.PLACEBEFORE );

                                        rep.position = rip;

                                        rep.resize( 31.414, 31.414, true, true, true, true, 100, Transformation.TOPLEFT );

                                        //doc.rasterItems[0].remove();

                                        ripObj.remove();

                                        rep.embed();

                                        opts = new PDFSaveOptions();

                                        opts.pDFPreset = '[Illustrator Default]';

                                        saveFile = File( outFolder + '/' + doc.name );

                                        doc.saveAs( saveFile, opts );

                                        doc.close( SaveOptions.DONOTSAVECHANGES );

                              };

                              app.userInteractionLevel = uIL;

                    } else {

                              alert( 'This Folder contained NO Illustrator PDF files?' );

                    };

          };

};

replaceImage();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 05, 2012 Oct 05, 2012

Copy link to clipboard

Copied

LATEST

Yes that fixed it. Thankyou v.much.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines