I would appreciate any help on a applescript command line that will change the page layout size from the standard 8.5" x 11" letter size to a larger custom size. Is this even possible? I can’t seem to find any info on the subject from Adobe or elsewhere…
Thanks as always!
Rod
Model: 733 mg G4
AppleScript: 1.9.1
Browser: Safari 85.8.1
Operating System: Mac OS X (10.2.x)
Unfortunately, Adobe made this a read only property (for both height and width)! Who knows why?!!?!
It may be a hack but you could always copy everything from an existing document and paste the contents into a newly Applescript created document. For whatever reason, the height and width are read only for existing documents but not for creation of them!
Jim Neumann
BLUEFROG
I’m using CS so I’m not sure about 10 but you can make a new document and give it a custom size as such:
tell application “Illustrator 10”
set docRef to make new document with properties {height:800,width:600}
end tell
The measurements are in points (72 / inch). Don’t know if this helps or not.
You’re quite welcome. Glad I could help.
psycodot:
Here’s something I hacked together if you need it.
set olddelims to AppleScript's text item delimiters
tell application "Illustrator CS" -- Will also work in AI 10.
activate
set selectedItems to selection of document 1
if selectedItems = {} then
set selection to (every page item of document 1)
end if
copy
set psize to (text returned of (display dialog "Enter page dimensions in inches:" & return & "(Ex. 8.5x11)" default answer ""))
set AppleScript's text item delimiters to "x"
set psize to (every text item of psize)
set pwidth to ((text item 1 of psize) as real) * 72
set pheight to ((text item 2 of psize) as real) * 72
set newDoc to make new document at beginning with properties {height:pheight, width:pwidth}
paste
close document 2 saving no -- You may want to change this or remove it if you want to be able to work with the previous document still.
end tell
set AppleScript's text item delimiters to olddelims
You can have selected items or it will select everything if nothing is selected. It also will close the originating document without saving it (which you can change if need be.)
Have Fun,
Jim Neumann
BLUEFROG
Bluefrog - Thanks for posting your code. I threw in some unlocking just in case there are layers or art in the file that are locked. If the script hits anything locked it’ll throw up an error. Of course, you could aways test for locked items and exclude them from the selection…
set olddelims to AppleScript's text item delimiters
tell application "Adobe Illustrator 10.0.3"
activate
set selectedItems to selection of document 1
if selectedItems = {} then --unlock each layer, then each object via loops
set theLayers to (every layer of document 1)
repeat with i from 1 to count of theLayers
set properties of item i of theLayers to {locked:false}
end repeat
set allStuff to (every page item of document 1)
repeat with i from 1 to count of allStuff
set properties of item i of allStuff to {locked:false}
end repeat
set selection to allStuff
end if
copy
set psize to (text returned of (display dialog "Enter page dimensions in inches:" & return & "(Ex. 8.5x11)" default answer ""))
set AppleScript's text item delimiters to "x"
set psize to (every text item of psize)
set pwidth to ((text item 1 of psize) as real) * 72
set pheight to ((text item 2 of psize) as real) * 72
set newDoc to make new document at beginning with properties {height:pheight, width:pwidth}
paste
close document 2 saving no -- You may want to change this or remove it if you want to be able to work with the previous document.
end tell
set AppleScript's text item delimiters to olddelims
mleslie: Nice catch. Like I said, it was hacked together quickly. Here’s a variation on your theme removing the repeat loop:
set olddelims to AppleScript's text item delimiters
tell application "Adobe Illustrator 10.0.3"
activate
set selectedItems to selection of document 1
if selectedItems = {} then
tell document 1
set unlockFunction to display dialog "Unlock Items on ." buttons {"Current layer", "All layers", "Cancel"}
if button returned of unlockFunction = "Current layer" then
set locked of current layer to false
set locked of every page item of current layer to false
set selection to (every page item of current layer)
else
set locked of every layer to false
set locked of every page item to false
set selection to (every page item)
end if
end tell
end if
copy
set psize to (text returned of (display dialog "Enter page dimensions:" & return & "(Ex. 8.5x11)" default answer ""))
set AppleScript's text item delimiters to "x"
set psize to (every text item of psize)
set pwidth to ((text item 1 of psize) as real) * 72
set pheight to ((text item 2 of psize) as real) * 72
set newDoc to make new document at beginning with properties {height:pheight, width:pwidth}
paste
close document 2 saving no -- You may want to change this or remove it if you want to be able to work with the previous document still.
end tell
set AppleScript's text item delimiters to olddelims
Cheers,
Jim Neumann
BLUEFROG
Hey Guys,
Consider posting the full solution on Code Exchange?
Nice, I’ll accept that option. Definitely runs faster that way.
However the lines that set the selection:
set selection to (every page item of current layer)
-- and ...
set selection to (every page item)
will hang with a “Handler only handles single objects”. Illustrator can be so picky how it would like to have things referenced… My workaround for that issue was to assign the page items to a variable before setting them as selected:
set allStuff to (every page item of document 1)
-- then...
set selection to allStuff
I’ve found that type of referencing necessary when applying colors/swatches to paths as well.
mleslie: Hmmm… I wonder if that’s a CS versus 10.0.3 thing ?!? I am running CS on my laptop and was too lazy to move 15 feet away to the tower with 10.0.3! Maybe we should take Ray up on this and post the 10.0.3 and CS versions!
From the looks of it you are no slouch at scripting. Hopefully I’ll get a look at some of your stuff in the near future. Right now I’m working on scripting the unscriptable and, besides beating the crap out of my brain, it’s some really cool stuff.
BLUEFROG