Apple Logo Itsamac Hosting
Mac OS Journal
EditorialsColumnsFeaturesReviewsArchives/StaffSubscribe
 
Table of Contents From the Desktop Connect Feature Column The CoXFiles The Gaming Landscape Warehouse The Surf Report Simply Web
Medicine Man The Database Guru The AppleScript Foundry Shop Talk Mac Mastery Review - Photoshop 6 Review - Beach Head 2000 Review - MiniPRO Mouse Behind the Scenes      
   
 
Itsamac.com
Red Light Runner
Applelust.com
     
 

The AppleScript Foundry
January 2001 || Volume 01, Issue 06

Back to the Drawing Board (Literally)... Illustrator AppleScripting

A couple of issues back, I wrote a review of Adobe Illustrator 9.0 that produced a lot of reader mail. Seems there were a lot of folks that found some things about Illustrator 9.0 that either didn't work they way they wanted or didn't work at all. In other words, they found some bugs. Recently, Adobe released 9.0.1 to address some of those issues. Version 9.0.1 is here. The list of items fixed in 9.0.1 is an 11 page long PDF file avaliable here. And now, version 9.0.2 is available here. Items fixed in 9.0.2 are mostly for Photoshop 6.0 compatiblity, but there are also some bug fixes. The list is available on the VersionTracker download page.

I still maintain that the program performed fine for me, and I stand by my review. However, there was one thing I missed, buried as it was on the Illustrator CD -- AppleScript support! It wasn't mentioned in the promotional material, but when a reader pointed it out, there it sat on the CD, waiting for me to find it. I can only say, "Mea culpa!" and beg your forgiveness (after all, it's a darned plug-in, not the normal sort of AppleScript extension you usually find).

In fact, the reader who pointed it out (Shane, who lives in Australia by his email address) sent along a couple of sample scripts he had written, and they are great examples of the sorts of things you can do with a scriptable Illustrator. Despite its somewhat odd implementation as an Illustrator plug-in, the scripting implementation itself seems to be full-featured, even supporting scripted EPS and PDF saves. It also supports a "do script" command that allows you to run Illustrator actions that you might already have put together to help you in your work.

Time, Please

Shane's first script, Time, Please, uses Illustrator to turn your Mac into a full screen analog clock. More than just impressive eye candy, this script illustrates (pun intended) the control you have over path items in AppleScript. You can rotate and move path items easily. Before you run this script, though, you should know that it uses full screen mode and will hide your menubar! Also, it was written to run continuously, so you will have to kill it in order to exit. You can do this by switching tasks to the "Time, Please" script using Command-Tab, then Command-Period will halt the script.

The script begins with the creation of a new CMYK document (that's Cyan, Magenta, Yellow and Black to those who aren't familiar with printing terms -- CMYK is the color space of printed documents as opposed to electronic documents that are Red, Green, and Blue [RGB]):

tell application "Adobe Illustrator¨ 9.0.1" make new document at beginning with
  properties {color space:CMYK}

The script continues with a tell block that tells the document to draw the clock face and update its parts (the hour, minute, and second hand) each time through the repeat loop.

tell document 1
set properties of view 1 to {screen mode:full screen, zoom:1, center point:{0, 0}}
activate
set windowBounds to bounds of view 1
set theRadius to ((item 2 of windowBounds) - (item 4 of windowBounds)) * 0.45
set innerRadius to theRadius * 0.9
set weigthFactor to theRadius / 100
make new ellipse at beginning with properties {bounds:{-theRadius, theRadius, theRadius, -theRadius}}

The variable theRadius is the radius of the clock face and also marks the end points of the hash marks at 3, 6, 9, and 12. The variable innerRadius is the inside circle that marks the interior ends of the hash marks around the clock face. Then Shane sets a path item up as:

set properties of path item 1 to {stroke width:weigthFactor, filled:true, opacity:100.0, stroke color:{class:CMYK color info, cyan:0.0, magenta:0.0, yellow:0.0, black:100.0}, fill color:{class:CMYK color info, cyan:0.0, magenta:0.0, yellow:20.0, black:0.0}, stroke dashes:{}, stroked:true}

And strokes the 3, 6, 9, and 12 positions:

repeat with anEndSet in {{{0, innerRadius}, {0, theRadius}}, {{0, -innerRadius}, {0, -theRadius}}, {{innerRadius, 0}, {theRadius, 0}}, {{-innerRadius, 0}, {-theRadius, 0}}}
  make new path item at beginning with properties {entire path:anEndSet, stroke width:4 * weigthFactor, filled:false, opacity:100.0, stroke cap:butted, stroke color:{class:CMYK color info, cyan:0.0, magenta:0.0, yellow:0.0, black:100.0}, stroke dashes:{}, stroked:true}
end repeat

Now if you remember your trigonometry (I don't either...), the other hour marks aren't as tidy as the first four. Shane got around this by using Illustrator's ability to rotate the path around the center point in 30¡ increments. I've marked the important line in underline to make it stand out for you:

repeat with i in {1, 2, 4, 5, 7, 8, 10, 11}
  make new path item at beginning with properties {entire path:{{0, innerRadius}, {0, theRadius}}, stroke width:weigthFactor, filled:false, opacity:100.0, stroke cap:butted, stroke color:{class:CMYK color info, cyan:0.0, magenta:0.0, yellow:0.0, black:100.0}, stroke dashes:{}, stroked:true}
  rotate path item
1 angle -i * 30 about document origin
end repeat

The remainder of the script draws the hour, minute, and second hands and updates them each time through the repeat loop, using the same techniques. If you would like to see the entire script, it's available from my public folder on my iDisk (login name: kevinbradley) at Apple's iTools site.

Eating Humble Pie

So now you have some idea of what you can do with a scriptable Illustrator. But what about something more practical?

If you are a user of older versions of ClarisWorks that doesn't support charting, you probably have looked in envy at folks who have new versions of AppleWorks or Microsoft Office who can generate charts easily from their spreadsheet data. Well, envy no more! Using the scripting capabilities of Illustrator, you can generate pie charts in a snap using Shane's other script, Humble Pie.

From Shane's Humble Pie Read Me file:

When run, it will ask you for a list of values (separated by spaces), or if it should instead use tab-delimited values on the clipboard ("Clip"). If you use the clipboard, you can have labels for the values; you want the clipboard to contain the equivalent of either a row of labels and a row of figures, or a column of labels and a column of figures (it's designed to deal with data copied from a spreadsheet).

You will then be asked for the radius of the chart in points; enter a suitable number.

The chart will be created on its own layer (called "Graph"). Each slice will be named ("Slice 1", etc.), as will each sample in the legend ("Sample 1", etc.) and its label ("Label 1", etc.). Each slice-and-sample pair will be grouped ("Group 1", etc.). For this reason, you should create only one chart per Illustrator document (you can copy and paste them later if you want). The graph will be centered in the page area.

The script colors the slices in greyscale percentages. It also gives them a 0.25-point black border (this can be changed; see the values strokeWidth and strokeColor near the top of the script).

Suffice to say that the Humble Pie script is much more complex than the Time, Please script, but it uses many of the same commands and techniques. I have also made it available to you on my public iDisk folder as a StuffIt file (Humble.sit) and I've added a version of Shane's readme file in AppleWorks 5 format for folks that don't own Word.

Final Analysis

The Illustrator AS suite has a lot of nice features. I am a little disappointed that it takes the form of a plug-in, though. I have had some problems getting Illustrator commands recognized in Apple's Script Editor or in the SMILE editor without Illustrator running. I'm not sure why Adobe chose such an odd implementation. Most applications include their dictionary in the application resources or as a scripting extension.

But AppleScript support is welcome in Illustrator. I hope that they also decide to add this functionality to Photoshop -- it's long overdue [Editor's Note: See this issue's Photoshop 6 review for more details about AppleScript support in this latest release.]

More About the AppleScript Foundry

Every month in the AppleScript Foundry, I'll be sharing what I know about scripting. Since the object of this column is to get people who are new to scripting up and running, I will take a hands on approach, explaining new terms along the way. However, it is not my goal to talk down to the reader - If you want harder stuff, just write me! You can reach me at kevin@macosjournal.com or you can use the handy web feedback form.

Here is a list of places you can go to get more info on AppleScript:

Kevin's Icon Kevin Bradley - kevin@macosjournal.com
Kevin's Page - Feedback Form

back Mac OS Journal forward
 
 
   
© 2000 - 2004, MacOSJournal.com. All rights reserved. No part of this publication may be reproduced in any way without prior, expressed permission from the Publisher. It is the sole property of MacOSJournal.com and its writers, who retain copyright to their own works. If you wish to link to us, please see our Privacy Statement for conditions. Apple, Macintosh, and Mac are trademarks of Apple Computer, Inc, with whom we are in no way affiliated or endorsed.
Hosting provided by itsamac.com -- Macintosh Powered Web Hosting
Serve Different