Exporting Illustrator files

Hi all:
Im trying to use this script, but it only makes the first document and try to over writte all documents with same name sends a time out error.
Any idea?


set targetFolder to choose folder with prompt "Location for exported files"
set targetPath to targetFolder as string

tell application "Adobe Illustrator 10"
	-- Turn off user interaction so dialogs don't cause the script to get stuck
	set user interaction level to never interact
	
	--	Count the open documents
	set documentCount to count documents
	
	--	Export each open document
	repeat with i from 1 to documentCount
		
		--	Get the document's name to use for creating a file path to save to
		set documentName to name of document 1
		
		--	Perform the save
		export document 1 to file (targetPath & documentName) as JPEG �
			with options {class:JPEG export options, quality:50, optimization:false, saving as HTML:false, horizontal scaling:200, vertical scaling:200}
	
	end repeat
end tell

Either change your references from “document 1” to “document i”, or add “close document 1 saving no” after the export. Your script is doing what it’s been asked to do.

Shane

As u seen i am very rookie, but i will follow trying to learn this tool.
Have my best regards :lol:

Resurrecting this very old thread, but I’m having a similar issue.

I’m trying to export a bunch of open AI files as PNG. I seem to be getting the references to the documents correctly as the new file name and path are being constructed correctly, but Illustrator keeps exporting whatever the frontmost document is, no matter which document is targeted. If I have 10 documents open, I get 10 docs with the correct names, but all have the same content as the frontmost doc.

Here’s a script without the repeats that I wrote to try to diagnose the issue. I have a TestDoc1 and TestDoc2 with text in each of them saying what they are. When TestDoc1 is frontmost, and I target TestDoc2 as below, a PNG is created with the TestDoc2 name but the TestDoc1 contents.


tell application "Adobe Illustrator"
	set myDoc to document 2
	set myPath to file path of myDoc as string
	set myShortName to text 1 thru -4 of myPath as string
	
	export myDoc to file (myShortName & ".png") as PNG24
end tell

Any idea where I’m going wrong? Or if this is really how it works, any ideas of a workaround, such as how to bring each targeted document to front so the correct file is exported?

Thanks in advance,

Mary

Illustrator CC 2019, Mac OS Catalina

Hi, Mary. Welcome to the forum. It’s a bug that’s easily worked around. AI references objects by indexes that shift to the last accessed item, so it’s preferable to start with a path list and open the documents individually.

set thelist to ((do shell script "find " & (my (choose folder)'s POSIX path)'s quoted form & space & "-name '*.ai' -depth 1")'s paragraphs)

tell application "Adobe Illustrator" to repeat with fileTarget in thelist
	open (fileTarget as POSIX file)
	tell document 1 to close (export to (fileTarget & ".PNG") as PNG24 with options {class:PNG24 export options, transparency:0}) without saving
end repeat

Thanks, Marc, for your quick reply. It’s much appreciated.

Too bad about the bug – I had a feeling that was going to be the answer! But at least that gives me a direction to go and quit banging my head on the wall.

Thanks again,

Mary
*Long-time lurker, first-time poster