Determining size of selection of multiple objects (Illustrator CS)

Pidge,

I’ll look into that as a last resort, mostly because it relies too heavily on a complex install for the script. In other words, install a script, an action, and a preset. Could make it all part of our standardized workstation deply, but it takes months to get images re-done. I’m always leary of preset files like these because they “vanish” or “get modified” at random (i.e. we suspect users fiddle but can’t prove it), causing support headaches.

Cool idea, didn’t even know Illustrator had an Actions palette. It’s never come-up before. :wink:

Plan right now is to wait for my Adobe Press scripting books. Though they say Javascript on the cover title, I’m told there is AppleScript in there too. My order of preference to solve this problem right now is:

AppleScript directly. Currently no efficient solutions, but the books may provide clues.

JavaScript via “do script” (which will likely be the books’ focus). I’ve never dealt with JavaScript beyond borrowing other people’s snippets and modifying them (I know enough about programming to modify, just never written one from scratch), but I’m not beyond learning enough to make this solution work if Illustrator is more accessible via JavaScript. I know PhotoShop is alot more scriptable via JavaScript.

Scripting the GUI. A bit kludgy but would work and be more efficient than the “check out every object in the document to determine total bounds” technique.

Scripting via Actions and Printer Presets. This one might be very efficient but lacks the portability aspect I prefer. I prefer to keep installs K.I.S.S. which this kinda goes against, especially if we share this script with partner vendors.

My books should arrive early next week, so it may be a couple days before I get back to y’all to give an update of which route I took.

The suggestions have all been most helpful and enlightening, I’ve got quite a few options to pick from now!

–Kevin

Hi Calvin,

Wich books have you ordered? I only now Adobe Illustrtor Scripting from Ethan Wilde. (And that’s not CS but older versions of Illustrator).

I have tried this code (as part of a script to print postscript files of Illustrator documents) and it works. Just figure out if it’s what I want to do (size correct and other things), so it’s need more testing.

set jobOpts to {class:job options, print area:artboard bounds, print as bitmap:true, file path:FullPath}

Can’t you use the ‘print area’ of the class ‘job options’ to get the correct size?

Why don’t try Xcode? My next project (well, after done all the projects I’m working on) is the research of combine Javascript (or other like Objective C) with applescript in Xcode.

Illustrator determines Print Area by default as the page size, near as I can tell. The designers often have a much larger “page size” when working than the artwork actually needs for the PDF. Hence this whole annoying little dilemma. :wink:

I’ll try again, but every time I’ve fiddled with those settings it keeps just spitting back the actual defined page size rather than the minimum outer bounds of the page elements as an aggregate.

How does this differ fundamentally with using AppleScript, JavaScript, and FaceSpan?

(And honestly I initially only used FaceSpan to add pretty GUI elements…I was very surprised how appreciated a simple progress bar can be. I also found it makes a handy way to “bundle” scripts that have external JavaScripts or Scripting Additions. Instead of all these “pieces” I can deploy a single application.)

–Kevin

Well to honestly … I don’t know FaceSpan. :wink:
But it sounds like it’s more or less the same. I only work with Xcode and AppleScript now, making the interface ‘good looking’ and makes the scripts work a lot faster as only using AppleScript. And true, with more scripts you can bundle it’s easier to programm things.

And the winner is…Toby!

Ironically, I got my Official Adobe JavaScript books, in which I found buried a link to download their AppleScript guides, which ironically are supposed to be on the install CDs anyway, but I don’t have access to the CDs. Bunch a bucks in books for a URL… :confused:

The first version I cooked-up based on the Adobe AppleScript guide was doing it the group way:


tell application "Illustrator CS"
	activate
	
	--group all objects in file
	set all_page_items to every page item of current document
	set group_ref to make new group item in current document
	move all_page_items to end of group_ref
	
	set group_width to width of group_ref
	set group_height to height of group_ref
end tell

Works like a charm, but a bit slow for a document containing thousands of objects. In the end, I wound-up with this:


tell application "Illustrator CS"
	activate
	
	--get document bounding box
	set bounding_box to the geometric bounds of current document
	
	--get dimensions of bounding box
	set doc_height to (item 2 of bounding_box) - (item 4 of bounding_box)
	set doc_width to (item 3 of bounding_box) - (item 1 of bounding_box)
	
end tell

Which of course is essentially Toby’s script. Actually I like Toby’s since I didn’t know you could do “properties in reverse” like that. So used to getting properties, then spreading them out one at a time to variables, had not idea that if you knew the relationship was 1:1 like that (or 4:4 if you will) that you could grab everything at once.

Going to give his a try to see if the code is valid either way, I’ll use Toby’s if it works.

Using geomtric bounds has a nice side benefit too…it compensates for stroke widths along the edges, which was something I thought I was going to have to “fudge” with some fixed number.

Thanks for everyone’s help!