Indesign Print Layers

Hi everyone I have been working on this applescript for weeks. It is made up from Olivier Berquin Print multiple ps from layers. I’m trying to print to a ps printer and have the files show up as “TestFile_layername” in the queue. So we can send the files as needed. The script works without changing the name, the files show up as "Testfile1.indd, Testfile2.indd, Testfile3.indd, etc… Basically the name of the file plus whatever number file it is when it is sent to the printer. When I try to change the name of the file I get this error…

Adobe InDesign CS2 got an error: Can’t set document “TestFile.indd” of document 1 to “TestFile_A002”.

I can’t figure out what I’m doing wrong. Can someone please look over my script and see if they can help me out in anyway.

Thanks

Heres the script:

tell application “Adobe InDesign CS2”
set allPresets to name of every printer preset
set printstyle to choose from list allPresets with prompt “Select Print Preset”
set mystyle to item 1 of printstyle

tell application "Finder"
	activate
	set mydoc to (choose file of type {"IDd4"} with prompt "Select InDesign Document to Print") as alias
	set docstring to (container of mydoc) as string
	set namedoc to name of mydoc
	set docextension to name extension of mydoc
	if docextension is not "" then set namedoc to (text 1 thru ((length of the namedoc) - (length of docextension) - 1) of namedoc)
end tell

tell application "Adobe InDesign CS2"
	open mydoc
	tell document 1
		set visible of every layer to false
		repeat with layername from 1 to count of layer
			set visible of every layer to false
			set visible of last layer to true
			set visible of layer layername to true
			set printlayername to name of layer layername
			set document name to (namedoc & "_" & printlayername)
			print using mystyle without print dialog
		end repeat
		close document saving no
	end tell
	beep
	display dialog "The Document has been Printed" buttons {"Done"} default button 1
end tell

end tell
end

After a lot of work and some help form co-workers we got it to work, but it does save a copy of the file which you can trash after the job prints.
So here it is…

tell application “Adobe InDesign CS2”
set allPresets to name of every printer preset
set printstyle to choose from list allPresets with prompt “Select Print Preset”
set mystyle to item 1 of printstyle

tell application "Finder"
	activate
	set mydoc to (choose file of type {"IDd4"} with prompt "Select InDesign Document to Save") as alias
	set docstring to (container of mydoc) as string
	set namedoc to name of mydoc
	set docextension to name extension of mydoc
	if docextension is not "" then set namedoc to (text 1 thru ((length of the namedoc) - (length of docextension) - 1) of namedoc)
	set savefolder to choose folder name with prompt "Select folder to Save files"
end tell

tell application "Adobe InDesign CS2"
	open mydoc
	tell active document
		set visible of every layer to false
		repeat with i from 1 to count of layer
			set visible of every layer to false
			set visible of last layer to true
			set visible of layer i to true
			set layername to name of layer i
			set printname to (namedoc & "-" & layername) as string
			set myFileName to savefolder & printname as string
			save to myFileName
			print using mystyle without print dialog
		end repeat
		close document saving no
	end tell
	beep
	display dialog "The Document has been Saved" buttons {"Done"} default button 1
end tell

end tell
end

Is it really neccessary to have the name of the document chage? You could build a slug box (on it’s own layer) and place it outside of the bleed area, then print the file while including the slug (Print dialog, marks & bleeds; last check box. Using thiis method you could build a custom print information slug and have the script print each with the appropriate layer name inserted in the slug box. When the slug is not needed you could then turn the slug layer off or just uncheck the include slug checkbox.

Jerome, What I was looking to do is print files to Store Queue on a printer. We have Indesign files that use the same 4/c art work with a type change on each one. So we build files with an artwork layer and name the other layers to correspond with the type change. So when the files show up in the printer queue they are name to each layer so we know which to print. But thanks for the suggestion.

fishheadtw