this forum is great
thanks for your job
PreTech,
you are correct here is the final code
tell application "Adobe Illustrator"
activate
tell document 1
repeat with i from 1 to (count of layers)
set visible of every layer to false
set visible of layer i to true
set NameOfLayer to name of layer i
set selection to every page item of layer i
-- you must group the everything on the layer to get the bounds of the objects
tell application "System Events"
tell process "Adobe Illustrator CS2"
click menu item "Group" of menu "Object" of menu bar 1
end tell
end tell
set sHeight to height of selection
set sWidth to width of selection
tell application "System Events"
--undoing the grouping will perserve your artwork
keystroke "z" using command down
end tell
copy selection
tell application "Adobe Illustrator"
make new document with properties {height:(sHeight + 5.0), width:(sWidth + 5.0)}
end tell
paste
save in ("" & ((path to current user folder) & ":Desktop:" & NameOfLayer & ".pdf")) as pdf
tell application "Adobe Illustrator"
close document 1 without saving
end tell
end repeat
end tell
close document 1 without saving
end tell
Jeanphilipee
your welcome
i’ve tested your code
but i’ve this error message :
Erreur dans System Events :
NSReceiverEvaluationsScriptError: 4
jeanphilippe,
Where does the error occur? Are you using the last code mcgrailm posted as it is or has it been modified?
PreTech
yes i’ve just tested this one
tell application "Adobe Illustrator"
activate
tell document 1
repeat with i from 1 to (count of layers)
set visible of every layer to false
set visible of layer i to true
set NameOfLayer to name of layer i
set selection to every page item of layer i
-- you must group the everything on the layer to get the bounds of the objects
tell application "System Events"
tell process "Adobe Illustrator CS2"
click menu item "Group" of menu "Object" of menu bar 1
end tell
end tell
set sHeight to height of selection
set sWidth to width of selection
tell application "System Events"
--undoing the grouping will perserve your artwork
keystroke "z" using command down
end tell
copy selection
tell application "Adobe Illustrator"
make new document with properties {height:(sHeight + 5.0), width:(sWidth + 5.0)}
end tell
paste
save in ("" & ((path to current user folder) & ":Desktop:" & NameOfLayer & ".pdf")) as pdf
tell application "Adobe Illustrator"
close document 1 without saving
end tell
end repeat
end tell
close document 1 without saving
end tell
and having error message
Where it the error occuring? Does it stop on a particular line?
PreTech
i’ve put this applescript in script folder of Illustrator CS2
and call it in script menu
at start, error message is :
Erreur dans System Events :
NSReceiverEvaluationsScriptError: 4
Have you tried just opening the script in Script Editor and running it from there? And if so have you had any errors there?
PreTech
whats the erro
I tried running the script from within Illustrator and the script runs, but does not give the same results as run from script editor. If you can run the script successfully from the editor, I would then save the script as an application and run it as a stand alone app. I’ve encountered this in Illustrator CS. I don’t know if this is a bug or not.
PreTech
P.S. Jeanphilippe, I just noticed that on one of your posts that you are running OS 10.0.1. You may not be able to use the system events code. That may require a system upgrade. You’ll have to code it without the UI Scripting.
Try this code:
set whereTo to path to desktop as string
tell application "Adobe Illustrator"
set fileName to "ill.pdf"
set t to current document
set c to count every layer of t
repeat with y from 1 to c
set lName to name of layer y of t
set thePath to whereTo & lName & fileName
my layerVis(thePath, lName)
end repeat
end tell
on layerVis(thePath, lName)
tell application "Adobe Illustrator"
set x to current document
set visible of every layer of x whose name is not lName to false
set visible of layer lName of x to true
save x in file thePath as pdf with options {class:PDF save options, compatibility:Acrobat 5}
end tell
end layerVis
This will make pdf’s of the layers the same size as the original document. If you need them to be the size of the bounds of the items in each layer, as mcgrailm’s code does, then we’ll have to add code to it to do this. This will save the pdf’s to the desktop with an ill.pdf attached to the name of each layer.
PreTech
ouaaahhhhh !
that’s what i want !
thanks a lot :)
thanks to all !!!
your code is free ? and can i use it and diffuse it ?
Certainly! You’re welcome!
PreTech
Hi Jean
Try This:
tell application "Illustrator CS"
activate
tell document 1
repeat with i from 1 to (count of layers)
set visible of every layer to false
set visible of layer i to true
set NameOfLayer to name of layer i
set selection to every page item of layer i
-- you must group the everything on the layer to get the bounds of the objects
tell application "System Events"
tell process "Adobe Illustrator CS2"
keystroke "g" using command down---> just changed this line
end tell
end tell
set sHeight to height of selection
set sWidth to width of selection
tell application "System Events"
--undoing the grouping will perserve your artwork
keystroke "z" using command down
end tell
copy selection
tell application "Illustrator CS"
make new document with properties {height:(sHeight + 5.0), width:(sWidth + 5.0)}
end tell
paste
save in ("" & ((path to current user folder) & ":Desktop:" & NameOfLayer & ".pdf")) as pdf
tell application "Illustrator CS"
close document 1 without saving
end tell
end repeat
end tell
close document 1 without saving
end tell
This is still Mcgrailm script just changed the one line sorry its in cs haven’t got cs2 here hope it works
Thanks Pidge 1
I keep your code in mind
but i prefer save pdf with page format.
At this time, i’ll use this solution :
set whereTo to path to desktop as string
tell application "Adobe Illustrator"
set fileName to "ill.pdf"
set t to current document
set c to count every layer of t
repeat with y from 1 to c
set lName to name of layer y of t
set thePath to whereTo & lName & fileName
my layerVis(thePath, lName)
end repeat
end tell
on layerVis(thePath, lName)
tell application "Adobe Illustrator"
set x to current document
set visible of every layer of x whose name is not lName to false
set visible of layer lName of x to true
save x in file thePath as pdf with options {class:PDF save options, compatibility:Acrobat 5}
end tell
end layerVis
tell application "Adobe Illustrator"
close document 1 without saving
end tell
Thanks again for your help .
A much neater solution than my first attempt. Worked well with some quick testing. No longer needs all that opening and closing files.
set Savefolder to choose folder with prompt "Where do you want to save the Files?"
set MyFile to choose file with prompt "Find your layered file" without invisibles
tell application "Finder"
set MyFile to MyFile as alias
end tell
--
tell application "Illustrator CS"
activate
open MyFile
set docRef to current document
tell docRef
set Colspace to get color space
set docHeight to height
set docWidth to width
set MyLayers to count of layers
set visible of every layer to true
set locked of every layer to false
set docName to name of docRef
set docBaseName to getBaseName(docName) of me
end tell
repeat with i from 1 to MyLayers
set NewDoc to make new document at end with properties ¬
{color space:Colspace, height:docHeight, width:docWidth}
set the current document to document docName
set LayerName to name of layer i of document docName as string
set theseitems to get every page item of layer i of document docName
repeat with thisitem in theseitems
duplicate thisitem to end of document 2
end repeat
set name of layer 1 of document 2 to LayerName
set newFileName to (Savefolder as string) & docBaseName & "-" & LayerName & ".pdf"
save document 2 in file newFileName as pdf with options ¬
{class:PDF save options, acrobat layers:true, changes allowed:pdf 128 any changes, color compression:automatic JPEG high, color downsampling:300, color downsampling threshold:450, color resample:bicubic downsample, compatibility:Acrobat 5, compress art:true, embed ICC profile:false, enable access:true, enable copy:true, enable copy and access:true, font subset threshold:100.0, generate thumbnails:true, grayscale compression:automatic JPEG high, grayscale downsampling:300, grayscale downsampling threshold:300, grayscale resample:bicubic downsample, monochrome compression:CCIT4, monochrome downsampling:300, monochrome downsampling threshold:450, monochrome resample:bicubic downsample, optimization:true, preserve editability:true, printer resolution:1200, registration marks:false, view pdf:false, page info:true}
close document 2 without saving
end repeat
end tell
----
on getBaseName(fName)
set baseName to fName
repeat with idx from 1 to (length of fName)
if (item idx of fName = ".") then
set baseName to (items 1 thru (idx - 1) of fName) as string
exit repeat
end if
end repeat
return baseName
end getBaseName
sorry,
don’t run for me
Error message : Erreur dans Adobe Illustrator : Impossible d’obtenir document 2