.remove() in script not removing item in some files
- March 3, 2022
- 2 replies
- 776 views
Hey y'all,
I wrote a script that runs against a folder you have your files saved in and is targeting rasterItems[0] within groupItems[1] within 'Layer 1' and I need to run it daily amongst hundreds of files. The problem that I'm facing is that on a large majority of files the script is working, but isn't working of files where the rasterItem I'm trying to remove is not being removed. The index of the rasterItem that isn't being deleted is the same index compared to the files where it is being deleted so I'm a bit confused as to why it's throwing an error. I will attach two files 1. the script will work perfectly for 2. The script throws the alert.
My script:
#target "Illustrator";
var myFolder = Folder.selectDialog (prompt);
var myFiles = myFolder.getFiles("*");
for(i=0; i<myFiles.length;i++){
var myDoc = app.open(myFiles[i]);
try{
app.activeDocument.layers["Layer 1"].groupItems[1].rasterItems[0].remove();
myDoc.close (SaveOptions.SAVECHANGES);
} catch(e){
alert(e);
}
}
For clarity, the target item is the faux silver and gold raster images in the files.
I appreciate any help and input with this!

