Adobe Illustrator Save Out Specific Layers To EPS

Hi all,

I’ve been searching on this site and elsewhere for awhile now, but I can’t quite get my script working.

What I’m trying to do is have Illustrator save out the respective layers that have my cutting path and registration marks to a new file with “-CUT” appended to it to the same directory as the open file. To do this it should:

• delete every layer except my cut and regmarks layers - this part works.

• delete all artboards except the first one - this does NOT work. It seems the last artboard is saved, not the first one.

• append “-CUT.” (I have to add that dot in there or it just saves over the original file) to the file name - this does NOT work correctly.

For some reason Illustrator always adds another file extension like so:

Original file - myfilename.eps

New file from script - myfilename.eps-CUT.eps

Here is the script I have so far:

tell application "Adobe Illustrator"
	
	set locked of every layer of the current document to false
	set visible of every layer of the current document to true
	set countArtboards to count artboards in document 1
	if countArtboards > 1 then
		delete artboard countArtboards of document 1
	else
		display alert "Cannot remove the only artboard in the document"
	end if
	delete (every layer of document 1 whose name does not start with "Cut" and name does not contain "regmark")
	set filepath to (file path of current document) as text
	set fileName to name of current document as text
	set fullPath to filepath & fileName
	set newFilePath to filepath & "-CUT."
	save current document in file newFilePath as eps with options {class:EPS save options, compatibility:Illustrator 13, preview:color TIFF, include document thumbnails:true, embed all fonts:true, CMYK PostScript:true, PostScript:level 2}
	close current document
end tell

So to sum up:

The script works, but it:

• saves the wrong artboard. I want it to only save the first artboard (maybe that if/then/else statement is not needed?)

• adds extra ‘.eps’ to the filename

I’d like to fix all this if possible. Thanks much for any help.

Well I kept hacking at this thing and I managed to get it mostly working.

I removed all the wonky artboard if/then statement code because I realized that could be set right in the EPS save options by setting save multiple artboards to true and artboard range to 1.

However, my filename appending is still not working. When I have:

AI TEST.eps

the script saves out my new file as:

AI TEST.eps-CUT-01.eps

I presume the “01” is the artboard number, but I don’t even want that in there. Ideally the file would save out as following:

AI TEST-CUT.eps

Here’s my code at this point:

tell application "Adobe Illustrator"
	
	set locked of every layer of the current document to false
	set visible of every layer of the current document to true
	delete (every layer of document 1 whose name does not start with "Cut" and name does not contain "regmark")
	set filepath to (file path of current document) as text
	set fileName to (name of current document) as text
	set fullPath to filepath & fileName
	set newFilePath to filepath & "-CUT."
	save current document in file newFilePath as eps with options {class:EPS save options, compatibility:Illustrator 13, save multiple artboards:true, artboard range:1, preview:color TIFF, include document thumbnails:true, embed all fonts:true, CMYK PostScript:true, PostScript:level 2}
	close current document without saving
end tell

Can anyone see how to adjust my code to accomplish this?

Grtz, Eric