![]() |
| |
![]() |
||
|
![]() |
||||||||||||||||||||||||||||||||
|
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 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 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}}} 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} 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:
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:
|
|||||||||||||||||||||||||||||||||
|