Adobe 26001360 Scripting Guide - Page 27
Handlers and subroutines, system to another
UPC - 718659321840
View all Adobe 26001360 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 27 highlights
Adobe Illustrator CS Scripting Guide 27 Handlers and subroutines Handlers (in AppleScript) or subroutines (in Visual Basic) are scripting modules you can refer to from within your script. Handlers and subroutines are ways to re-use parts of scripts. Typically, you send one or more values to a handler (or subroutine), and it returns one or more values. Handlers (and subroutines) can be used for performing conversions from one measurement system to another, or for calculating the geometric center point of an object from its geometric bounds. There's nothing special about the code used in subroutines and handlers-they are simply conveniences that save you from having to type the same lines of code over and over again in your script. If you find yourself typing or pasting the same lines of code into several different places in a script, you've identified a good candidate for a subroutine or handler. AppleScript -- Calculate the geometric center of a selected art item -- Assumes you have a single art item selected tell application "Adobe Illustrator CS" -- Get the selection from the current document set selectedItems to selection (* Make sure there is a selected item, and that the selection is not text *) if selectedItems ≠ {} and class of selectedItems ≠ text then -- Get the first item from the list and get it bounds set firstItem to item 1 of selectedItems set itemBounds to geometric bounds of firstItem end if end tell set itemCenter to GetItemCenter(itemBounds) display dialog "Center x:" & item 1 of itemCenter & ", y:" & item 2 of itemCenter -- This handler finds the center of an item given its bounds on GetItemCenter(itemBounds) -- Assign coordinates from the bounds to individual variables set {itemLeft, itemTop, itemRight, itemBottom} to itemBounds -- Calculate the center position set xCenter to (itemLeft + itemRight) / 2 set yCenter to (itemTop + itemBottom) / 2 return {xCenter, yCenter} end GetItemCenter 12 Aug 03