I'm working on a javascript that goes through a folder, rasterizes the paths inside each file, and saves the results as separate files in another folder. My script works fine on individual files as well as for several simple files. However, once it gets going on some of the big ones, it starts to give me PARM errors.
What I'm working with:
- Illustrator CS5.1
- Windows XP, SP3 (work computer)
- Javascript
- The CAD export that created the pdf and eps files broke any curves into tons of tiny straight lines. As a result, these drawings can have 15-35 thousand paths per image.
Summary of my code:
- Get the source and destination directories
- Open a file from the source directory
- Go to the first layer of the file
- Loop through all text items to move them to their own layer
- Loop through all path and compound paths to move them to a group
- Rasterize the group of path items
- Repeat for the next layer and so on
- Save the file to the destination directory
- Repeat the process for the next file and so on
The scripting guide suggests it could be from conflicting functions or global variables overwriting each other. However, my script is now entirely contained within its own function, and all variables are declared locally. Running from a clean illustrator and ESTK startup, it will still produce a PARM error after a few large files.
The guide also suggests having the script quit and re-launch Illustrator after working on many files. Since I assume these huge diagrams are probably several "normal" files' worth of objects each, I figured it probably just needs to restart Illustrator after x amount of stuff goes through. So I look in the guide's section on launching Illustrator through javascript. That basically says "Why would you ever need to do that?" Gee, thanks. I tried looking it up in the tools guide, but that document isn't very clear at all.
So, onto my actual questions:
1. What would I have to do so Illustrator doesn't throw a PARM error on the line marked below? (besides just putting it in a try/catch and pretending it didn't happen) It doesn't consistently happen on the same file or even at the same point in the file, but always at that line.
This is just a tiny part of the script. objectClass is a placeholder for PathItems, CompoundPathItems, etc. Looping backwards and setting the group to null at the end were just experiments, neither of which had any effect on the error.
if(objectClass.length > 0){ var objectGroup = myLayer.groupItems.add(); for(var i = objectClass.length; i > 0; i--){ objectClass[i-1].move(objectGroup, ElementPlacement.PLACEATBEGINNING); //This one keeps breaking stuff. } sourceDoc.rasterize(objectGroup, rastBounds, rastOptions); objectGroup = null;
}
2. Failing that, how can I relaunch Illustrator through javascript? Or a limited amount of VBScript, though my knowledge of that is limited too.