Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

Script that worked now giving a 1302 error

$
0
0

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[i] );

 

                                        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();


Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>